val.js | Код | $.fn.copyTo = function(to) { var to = $(to); for ( var i = 1; i < arguments.length; i++ ) to.set( arguments[i], this.get(0)[ arguments[i] ] ); return this; };
new function() {
// $.fn.validate = validate() {}; $.fn.validate = { init: function(o) { if(o.name == 'username') { this.username(o) }; if(o.name == 'password') { this.password(o) }; if(o.name == 'email') { this.email(o) }; },
username: function(o) { var username = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/; if (!o.value.match(username)) {doSuccess(o);} else {doError(o,'no special characters allowed');};
var usernames = /[а-я]/; if (!o.value.match(usernames)) { doSuccess(o); } else { doError(o,'Некорректный логин'); };
},
password: function(o) { var pass = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/; if (!o.value.match(pass)) {doSuccess(o);}
else {doError(o,'no special characters allowed');}
if(o.value.length > 6) {doSuccess(o); }
else {doError(o,'Пароль меньше 6 символов');}
},
email: function(o) { var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (o.value.match(email)) { doSuccess(o); } else { doError(o,'Некорректный e-mail адрес'); }; }, };
function doSuccess(o) { $('#' + o.id + '_img').html('<img src="accept.gif" border="0" style="float:left;" />'); $('#' + o.id + '_li').removeClass("error"); $('#' + o.id + '_msg').html(""); $('#' + o.id + '_li').addClass("success"); }
function doError(o,m) { $('#' + o.id + '_img').html('<img src="exclamation.gif" border="0" style="float:left;" />'); $('#' + o.id + '_li').addClass("error"); $('#' + o.id + '_msg').html(m); $('#' + o.id + '_li').removeClass("success"); }
};
$.fn.match = function(m) { $('#' + this.get(0).id + '_img').html('<img src="loading.gif" border="0" style="float:left;" />'); if ($(this).get(0).val() == $(m.match).val()) { $('#' + this.get(0).id + '_img').html('<img src="accept.gif" border="0" style="float:left;" />'); $(m.error).removeClass("error"); $(m.error).addClass("success"); $('#' + this.get(0).id + '_msg').html(""); } else { $('#' + this.get(0).id + '_img').html('<img src="exclamation.gif" border="0" style="float:left;" />'); $(m.error).addClass("error"); $(m.error).removeClass("success"); $('#' + this.get(0).id + '_msg').html("Ваши пароли не совпадают"); }; };
$(document).ready(function() {
$("//[@class=validated]/input").blur(function() { $(this).validate.init(this); });
$("#confirmpass").blur(function() { $(this).match({match: '#password', error: '#confirmpass_li'}); });
// This Used To Be HOVER, But I.E. Didnt Like It //$(".form li").hover(function(){$(this).addClass("selected");},function(){$(this).removeClass("selected");}); $(".form li").mouseover(function() { $(this).addClass("selected"); }); $(".form li").mouseout(function() { $(this).removeClass("selected"); }); });
|
Сами ячейки | Код | <ul class="form">
<li class="validated" id="username_li"> <label for="r_username">Введите логин:</label> <div id="username_img"></div> <input class="validated" name="username" id="username" type="text" maxlength="20" value="" /> <div id="username_msg"></div> </li>
<li class="validated" id="password_li"> <label for="r_password">Введите пароль:</label> <div id="password_img"></div> <input name="password" id="password" type="password" maxlength="20" /> <div id="password_msg"></div> </li>
<li id="confirmpass_li"> <label for="r_confirmpass">Повторите пароль:</label> <div id="confirmpass_img"></div> <input name="r_confirmpass" id="confirmpass" type="password" maxlength="20" /> <div id="confirmpass_msg"></div> </li>
<li class="validated" id="email_li"> <label for="email">email:</label> <div id="email_img"></div> <input name="email" id="email" type="text" maxlength="20" /> <div id="email_msg"></div> </li>
</ul>
|
Подскажите пожалуйста как создать новую ячейку что бы она работала как эти, я делаю | Код | <li class="validated" id="test_li"> <label for="test">test:</label> <div id="test_img"></div> <input name="test" id="test" type="text" maxlength="20" /> <div id="test_msg"></div> </li>
|
И добавляю | Код |
test: function(o) { var test = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/; if (!o.value.match(test)) {doSuccess(o);} else {doError(o,'no special characters allowed');};
var t = /[а-я]/; if (!o.value.match(t)) { doSuccess(o); } else { doError(o,'tete'); };
},
|
подскажите пожалуйста почему оно не работает
|