The HTML code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<link href= "Css/style.css" rel= "stylesheet" type= "Text/css"/>
<!--Introducing jquery--
<script src= ". /scripts/jquery-1.3.1.js "type=" Text/javascript "></script>
<script type= "Text/javascript" >
//<! [cdata[
$ (function () {
//If required, add Red Star logo
$ ("form:input.required"). each (function () {
var $required = $ ("<strong class= ' High ' > *</strong>");//Create elements
$ (this). Parent (). append ($required);//And append it to the document
});
//After the text box loses focus
$ (' Form:input '). blur (function () {
var $parent = $ (this). parent ();
$parent. Find (". Formtips"). Remove ();
//Verify user name
if ($ (this). is (' #username ')) {
if (this.value== "" | | This.value.length < 6) {
var errormsg = ' Please enter a user name of at least 6 bits. ';
$parent. Append (' <span class= ' formtips onError ' > ' +errormsg+ ' </span> ');
}else{
var okmsg = ' input correct. ';
$parent. Append (' <span class= ' formtips onsuccess ' > ' +okmsg+ ' </span> ');
}
}
//Verify Mail
if ($ (this). is (' #email ')) {
if (this.value== "" | | (this.value!= "" &&!/[email protected]+\. [A-za-z] {2,4}$/.test (this.value)) {
var errormsg = ' Please enter the correct e-mail address. ';
$parent. Append (' <span class= ' formtips onError ' > ' +errormsg+ ' </span> ');
}else{
var okmsg = ' input correct. ';
$parent. Append (' <span class= ' formtips onsuccess ' > ' +okmsg+ ' </span> ');
}
}
}). KeyUp (function () {
$ (this). Triggerhandler ("blur");
}). focus (function () {
$ (this). Triggerhandler ("blur");
});//end Blur
//Submit, Final verification
$ (' #send '). Click (function () {
$ ("form:input.required"). Trigger (' blur ');
var numerror = $ (' form. OnError '). length;
if (numerror) {
return false;
}
Alert ("Registration is successful, password has been sent to your mailbox, please check.");
});
//reset
$ (' #res '). Click (function () {
$ (". Formtips"). Remove ();
});
})
//]]>
</SCRIPT>
<body>
<form method= "POST" action= "" >
<div class= "int" >
<label for= "username" > User name:</label>
<input type= "text" id= "username" class= "required"/>
</div>
<div class= "int" >
<label for= "Email" > Email:</label>
<input type= "text" id= "email" class= "required"/>
</div>
<div class= "int" >
<label for= "Personinfo" > Profile:</label>
<input type= "text" id= "Personinfo"/>
</div>
<div class= "Sub" >
<input type= "Submit" value= "commit" id= "send"/><input type= "reset" id= "res"/>
</div>
</form>
</body>
An example of a simple form validation in jquery