jQuery Form Validation, Only Allow .EDU Email Addresses

前端 未结 3 769
无人及你
无人及你 2020-12-19 16:13

I am using the jquery validate function and plugin located here. http://docs.jquery.com/Plugins/Validation

I am going thrue the js file and i have found the email va

3条回答
  •  执念已碎
    2020-12-19 16:57

    You don't need custom extension. You can use accept() method: http://docs.jquery.com/Plugins/Validation/Methods/accept#extension

    // input field
    
    
    // validation rule
    eduEmail2: {
        required: true,
        email: true,
        accept: 'edu'
    }
    

    Full example: http://jsfiddle.net/M5TmU/2/ (based on Brombomb's jsfiddle)

    UPDATE

    After xecute's comment - you may use custom regex pattern. In additional-methods.js you have "pattern" method (last one in a file):

    eduEmail3: {
        required: true,
        email: true,
        pattern: /(\.edu\.\w\w)$/
    }
    

    Full example: http://jsfiddle.net/M5TmU/3/

    Of course it's not perfect, but still - you don't need write custom method :)

    ADDITIONAL EDIT: country domain names have two letters, so \w\w\w? is too much - \w\w should do. I left \w\w\w? in fiddle

提交回复
热议问题