jQuery的表单验证,只允许.EDU电子邮件地址 [英] jQuery Form Validation, Only Allow .EDU Email Addresses
问题描述
我使用设在这里的JQuery验证功能和插件。 http://docs.jquery.com/Plugins/Validation
I am using the jquery validate function and plugin located here. http://docs.jquery.com/Plugins/Validation
我要thrue的js文件,我已经找到了电子邮件验证块可以确保它是一个有效的电子邮件,事情是,我想只允许埃杜电子邮件。我不知道从哪里开始。
I am going thrue the js file and i have found the email validation block that makes sure it is a valid email, the thing is, i want to only allow .edu emails. I have no idea where to start.
推荐答案
您不需要自定义扩展。您可以使用接受()
方法:<一href="http://docs.jquery.com/Plugins/Validation/Methods/accept#extension">http://docs.jquery.com/Plugins/Validation/Methods/accept#extension
You don't need custom extension. You can use accept()
method: http://docs.jquery.com/Plugins/Validation/Methods/accept#extension
// input field
<input type="text" id="eduEmail2" name="eduEmail2" value="abc@123.edu"/>
// validation rule
eduEmail2: {
required: true,
email: true,
accept: 'edu'
}
完整的例子: http://jsfiddle.net/M5TmU/2/ (基于Brombomb的的jsfiddle)
Full example: http://jsfiddle.net/M5TmU/2/ (based on Brombomb's jsfiddle)
更新
在xecute的评论 - 您可以使用自定义的正则表达式。在额外-methods.js
你有模式
的方法(最后一个文件):
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)$/
}
完整的例子: http://jsfiddle.net/M5TmU/3/
当然,它并不完美,但还是 - 你不需要编写自定义的方法:)
Of course it's not perfect, but still - you don't need write custom method :)
其他修改:国家域名有两个字母,所以 \ W \ W \ W
实在是太多了 - \ W \ W
应该做的。我离开 \ W \ W \ W?
在拨弄
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
这篇关于jQuery的表单验证,只允许.EDU电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!