<div class="codetitle"> <span><a style="CURSOR: pointer" data="71566" class="copybut" id="copybut71566" onclick="doCopy('code71566')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code71566"> <br><script type="text/javascript"> <br> //More verifications can continue to be added to the errMsg object <br>var errMsg={ <br>required:{ <br>msg: "This field is required.", <br>//The load parameter specifies whether it is loading When verifying <br>test:function(obj,load){ <br>return obj.value.length > 0 || load || obj.value==obj.defaultValue; <br>} <br>}, <br>//Verification email<br>email:{ <br>meg:"Not a valid email address.", <br>test:function(obj){ <br>return /^[a-z0-9A- Z _.-] @([a-z0-9A-Z-_] .) [a-z0-9]{2,4}$/i.test(obj.value); <br>} <br> }, <br>//Verification URL<br>url:{ <br>msg:"Not a valid URL.", <br>test:function(obj){ <br>return obj.value=="http: //" || /^https?://([a-z0-9-] .) [a-z0-9]{2,4}.*$/.test(obj.value); <br> } <br>} <br>} <br>//Example <br>onload=function(){ <br>$("url").onblur=function(){ <br>if(errMsg.url.test (this)){ <br>alert("right"); <br>}else{ <br>alert(errMsg.url.msg); <br>} <br>} <br>} <br>< /script> <br> </div>