您现在的位置是:网站首页> 编程资料编程资料
Javascript Validation for email(正则表达式) 英文翻译_正则表达式_
2023-05-25
353人已围观
简介 Javascript Validation for email(正则表达式) 英文翻译_正则表达式_
Try testing the following form with valid and invalid email addresses. The
code uses javascript to match the users input with a regular expression.
函数代码:
function validate(form_id,email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value;
if(reg.test(address) == false) {
alert('Invalid Email Address');
return false;
}
}
In the forms ‘onsubmit' code call javascript:return validate(‘form_id','email_field_id')
使用方法:
You should not rely purely on client side validation on your website / web application, if the user has javascript disabled this will not work. Always validate on the server.
from: http://www.white-hat-web-design.co.uk/blog/javascript-validation/
code uses javascript to match the users input with a regular expression.
函数代码:
复制代码 代码如下:
function validate(form_id,email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value;
if(reg.test(address) == false) {
alert('Invalid Email Address');
return false;
}
}
In the forms ‘onsubmit' code call javascript:return validate(‘form_id','email_field_id')
使用方法:
复制代码 代码如下:
You should not rely purely on client side validation on your website / web application, if the user has javascript disabled this will not work. Always validate on the server.
from: http://www.white-hat-web-design.co.uk/blog/javascript-validation/
您可能感兴趣的文章:
相关内容
- 学php正则!超基础简单例子_正则表达式_
- asp提取内容中的手机号码,qq,网址的正则代码_正则表达式_
- PHP 正则表达式特殊字符 [:alnum:] [:alpha:] 等_正则表达式_
- 正则表达式之捕获组/非捕获组介绍_正则表达式_
- 匹配yyyy-mm-dd日期格式的的正则表达式_正则表达式_
- js正则函数match、exec、test、search、replace、split使用介绍集合_正则表达式_
- JS正则中的match与exec使用说明_正则表达式_
- 检查素数的正则表达式分享_正则表达式_
- PHP匹配多行的正则表达式分析_正则表达式_
- 用正则表达式判断字符串是汉字还是拼音的js函数代码_正则表达式_
