我不是在问完整的电子邮件验证.
我只是想知道电子邮件地址中允许的字符user-name和server部分内容.这可能过于简单,也许电子邮件地址可以采取其他形式,但我不在乎.我只询问这个简单的形式:( user-name@server例如wild.wezyr@best-server-ever.com)和两个部分允许的字符.
我想,以验证电话号码,如123-345-3456和(078)789-8908使用JavaScript.这是我的代码
function ValidateUSPhoneNumber(phoneNumber) {
var regExp = /^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}/;
var phone = phoneNumber.match(regExp);
if (phone) {
alert('yes');
return true;
}
alert('no');
return false;
}
Run Code Online (Sandbox Code Playgroud)
我正在测试使用的函数ValidateUSPhoneNumber('123-345-34567'),该函数在最后一个连字符之前有5位数,根据正则表达式无效.但该函数返回true.任何人都可以解释原因吗?
我需要在注册表单中验证我想要一个正则表达式的文本字段.
文本框将接受手机号码,如9999999999(10位数 - 从7或8或9开始).用户也可以写+919999999999,其中+91是国家代码(印度为+91,但可以接受任何其他类似+110或+52),或者他也可以写09999999999(自己国家的前0)
在这里,用户有3个选择,
虽然不是必需的,但我的页面是在asp.net中,我使用的是内置的正则表达式验证器.
提到这个问题:
<form id="new_invitation" class="new_invitation" method="post" data-remote="true" action="/invitations" accept-charset="UTF-8">
<div id="invitation_form_recipients">
<input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_0"><br>
<input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_1"><br>
<input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_2"><br>
<input type="text" value="" name="invitation[recipients][]" id="invitation_recipients_3"><br>
</div>
<input type="submit" value="Send invitation" name="commit">
</form>
Run Code Online (Sandbox Code Playgroud)
使用jquery为字段设置最小长度的代码?
$('#new_invitation').submit(function(event) {
if ($('#invitation_form_recipients input').filter(function() {
return $(this).val();
}).length == 0) {
// all the fields are empty
// show error message here
// this blocks the form from submitting
event.preventDefault();
}
});
Run Code Online (Sandbox Code Playgroud)
如何验证每个字段输入是否具有jquery的有效电子邮件地址?在上面的代码?
谢谢!
$('#new_invitation').submit(function(e) {
$('#invitation_form_recipients input').each(function(e) { …Run Code Online (Sandbox Code Playgroud)