Validate email address textbox using JavaScript

前端 未结 10 844
一个人的身影
一个人的身影 2020-12-02 17:03

I have a requirement to validate an email address entered when a user comes out from the textbox.
I have googled for this but I got form validation JScript; I don\'t wa

10条回答
  •  自闭症患者
    2020-12-02 17:33

    Assuming your regular expression is correct:

    inside your script tags

    function validateEmail(emailField){
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    
            if (reg.test(emailField.value) == false) 
            {
                alert('Invalid Email Address');
                return false;
            }
    
            return true;
    
    }
    

    in your textfield:

    
    

提交回复
热议问题