我想验证我的登记表,但每份案文投入都有违约值。 将所有可能的方法与杂草鉴定成泡。 它难以理解如何使用它(一刀切)) 想要做的是,忽视了缺省价值和确认形式。 我的样子认为:
<from id="reg">
<input class="part1 default" type="text" name="fname" id="fname" value="Adınız (First Name)"/>
<input class="part1 default" type="text" name="mname" value="Atanızın adı (Middle name)"/>
</form>
采用这一代法
var defaultValues = {
fname : Adınız ,
mname : Atanızın adı ,
lname : Soyadınız ,
phone : Telefon ,
email : Email ,
pwd : Şifrə ,
region : Rayon ,
school : Məktəb ,
login : Istifadəçi adı ,
class : Sinif ,
subject : Fənnin adını daxil edin ,
dob : Date of Birth
};
$( input ).live( focus , function() {
var el = $(this);
if (el.hasClass( default )) {
el.removeClass( default ).val( );
}
if (el.attr( id ) === dob ) {
$(this).mask( 99.99.9999 , {placeholder: });
}
});
$( input ).live( blur , function() {
var el = $(this);
var name = el.attr( name );
// Really we only want to do anything if the field is *empty*
if (el.val().match(/^[s.]*$/)) {
// To get our default style back, we ll re-add the classname
el.addClass( default );
// Unmask the dob field
if (name == dob ) {
el.unmask();
}
// And finally repopulate the field with its default value
el.val(defaultValues[name]);
}
});
/*validation*/
$( #reg ).submit(function (event)
{
if ($( #fname ).val() == defaultValues[ Adınız ] || $.trim($( #pwd ).val()) == )
{
alert( Please enter the name! );
return false;
}
else
{
if ($( #fname ).val().length < 2)
{
alert( The name must be >2 letters! );
return false;
}
}
});
你看到的最后一个部分是鉴定。 我对此有如下问题:
- Lets say we wrote if s for all possible cases. What if allright and we want to continue submitting process? Do i need to write new if for it and end this if with "return true?"
- I used this piece of code but it always gives me the same error message "Please enter a password!" even if all input fields are filled. How can we modify this code to alert the array of errors? for example if my pass is wrong type and name field unfilled the script will show 2 errors at once. I thought about logic too: For example every time when some case is true then it pushes to array the error message and when it finishes checking all cases, shows the error array. But can t realise it. How to validate email field, and date of birth field (looks like "19.16.2010")?