Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make custom HTML 5 email validation

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 298
    Comment on it

    Hello Reader! If you have been working with HTML 5 validation then on incorrect email address web broser will show the default error message "please enter a valid email address". Now you can make it custom and write your own message. Lets see the code below:-

    Then HTML form is as same:-

    <form id="myform">
        <input id="email" oninvalid="InvalidMsg(this);" name="email" oninput="InvalidMsg(this);"  type="email" required="required" />
        <input type="submit" />
    </form> 
    

    Now in the JS code :-

    function InvalidMsg(textbox) {
    
        if (textbox.value == '') {
            textbox.setCustomValidity('Required email address');
        }
        else if(textbox.validity.typeMismatch){
            textbox.setCustomValidity('please enter a valid email address'); //write your custom code here
        }
        else {
            textbox.setCustomValidity('');
        }
        return true;
    }
    

    As you can now put your own custom message on 'text.setCustomValidity'

    Source By :- jsfiddle.net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: