Home >Web Front-end >JS Tutorial >jQuery simply implements verification email format_jquery
You may need to use the email verification code when submitting the form. The code is relatively simple, just to determine the email format. If there is any difficulty, it may be about the use of regular expressions. I won’t go into details here. You can check it yourself. , here is a piece of verification code that can be used, just copy and paste it.
The code example is as follows:
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#bt").click(function(){ if($("#email1").val()=="") { alert("邮箱不能为空"); return false; } var email=$("#email1").val(); if(!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/)) { alert("格式不正确!请重新输入"); $("#email1").focus(); } }) }) </script> </head> <body> <form action="#"> <input type="text" id="email1"> <input type="button" value="提交" id="bt"> </form>
The above code implements simple email verification, and it can be used after assigning and pasting the code.
The above is the entire content of this article, I hope you all like it.