Javascript Validation for email(正则表达式) 英文翻译
2019/6/29 21:04:19
本文主要是介绍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')
使用方法:
<form id="form_id" method="post" action="action.php" onsubmit="javascript:return validate('form_id','email');">
<input type="text" id="email" name="email" />
<input type="submit" value="Submit" />
</form>
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')
使用方法:
复制代码 代码如下:
<form id="form_id" method="post" action="action.php" onsubmit="javascript:return validate('form_id','email');">
<input type="text" id="email" name="email" />
<input type="submit" value="Submit" />
</form>
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/
这篇关于Javascript Validation for email(正则表达式) 英文翻译的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-11正则表达式学习:入门指南与实践技巧
- 2024-08-15正则表达式入门:基础教程与实践指南
- 2024-01-0939. 干货系列从零用Rust编写负载均衡及代理,正则及格式替换
- 2024-01-08如何编写高效的正则表达式?
- 2023-12-29"Matlab中的正则表达式:强大而灵活的工具"
- 2023-09-30这个正则 为啥同样的单号第二个就提取不出来?
- 2023-06-086.2 re 正则表达式
- 2023-06-06将字符串里的\x01,\x02这些替换掉用正则表达式无效?
- 2023-05-24正则表达式详解
- 2023-05-17我让gpt写了一段正则表达式代码,可是运行报错,可以帮忙看看哪里出了问题?