您好我有一個形式引用到電子郵件輸入字段提交的輸入,當用戶點擊提交按鈕,我想以確保電子郵件輸入字段值具有這樣的形式
[email protected]
或
[email protected]
或
[email protected]
和輸入字段是該
<p>
<label>Email</label>
<input type="text" name="Email"/>
<span class="errorMessage"></span>
</p>
jQuery代碼
$(document).ready(function(){
$('#suform').on('submit', function(e){
e.preventDefault();
var errorCount = 0;
$('span.errorMessage').text(''); // reset all error mesaage
$('input').each(function(){
var $this = $(this);
if($this.val() === ''){
var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
$this.next('span').text(error);
errorCount = errorCount + 1;
}
});
if(errorCount === 0){
var mobileNumber = $('input[name=MNumber]');
var email = $('input[name=Email]');
if(isNaN(parseFloat(mobileNumber)) && !isFinite(mobileNumber)) {
var error = 'Mobile number incorect.';
$('input[name=MNumber]').next('span').text(error);
errorCount = errorCount + 1;
}else{
var password= $('input[name="Password"]').val();
var repass= $('input[name="RePassword"]').val();
if(password!=repass){ // ensrue the two passwords are the same
var error2 = 'Password not matching';
$('input[name="RePassword"]').next('span').text(error2)
errorCount = errorCount + 1;
}else{
$(this)[0].submit(); // submit form if no error
}
}
}
});
});
我的HTML,CSS和jQuery代碼是在這裏 code
問題是什麼?什麼不工作? – gdoron
http://stackoverflow.com/questions/2855865/jquery-validate-e-mail-address-regex – Dhiraj