简体   繁体   English

为什么验证中的HTML不起作用?

[英]Why html from validation doesn't work?

I have this HTML form and try to validate at client side. 我有此HTML表单,并尝试在客户端进行验证。 This is the validation function at HTML form. 这是HTML表单的验证功能。

function registerValidate() {
    var have_error = "No";
    var email = $('#userEmail').val();
    var pwd = $('#password').val();
    var pwdr = $('#passwordr').val();
    var email_re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;

    if (!email.match(email_re)) { 
       $('#email-error').html('Please enter a valid email');
        have_error = "Yes";
    }else{
        $('#email-error').html('');    
    } 

}

When I click "Create My Account", all texts filled inside the text inputs disappeared and doesn't show the error message, even it should show error message. 当我单击“创建我的帐户”时,填充在文本输入中的所有文本都消失了,并且没有显示错误消息,甚至应该显示错误消息。

What could be wrong? 有什么事吗

When do you call this function? 什么时候调用此函数? On form submit? 在表格上提交? Maybe you form have been submitted and all data field cleared. 也许您的表格已经提交并且所有数据字段都已清除。 Could you provide source code? 您能提供源代码吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM