Imは、フォームの検証が、イムだけで、姓と名のフィールドuは助けることができる唯一の文字入力
の希望のために手紙を受け入れるようにそれを得るのに苦労するためのフォームを検証
HERESに私のコード:
$(document).ready(function(){
// Place ID's of all required fields here.
required = ["firstname", "lastname", "email"];
// If using an ID other than #email or #error then replace it here
email = $("#email");
errornotice = $("#error");
// The text to show up within a field when it is incorrect
emptyerror = "Please fill out this field.";
emailerror = "Please enter a valid e-mail.";
onlyletters = "Only letters allowed.";
$("#theform").submit(function(){
//Validate required fields
for (i=0;i<required.length;i++) {
var input = $('#'+required[i]);
if ((input.val() == "") || (input.val() == emptyerror)) {
input.addClass("needsfilled");
input.val(emptyerror);
errornotice.fadeIn(750);
} else {
input.removeClass("needsfilled");
}
}
// Only Letters.
if (!/^([a-zA-Z])+$/.test(errornotice.val())) {
errornotice.addClass("needsfilled");
errornotice.val(onlyletters);
}
// Validate the e-mail.
if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
email.addClass("needsfilled");
email.val(emailerror);
}
//if any inputs on the page have the class 'needsfilled' the form will not submit
if ($(":input").hasClass("needsfilled")) {
return false;
} else {
errornotice.hide();
return true;
}
});
// Clears any fields in the form when the user clicks on them
$(":input").focus(function(){
if ($(this).hasClass("needsfilled")) {
$(this).val("");
$(this).removeClass("needsfilled");
}
});
});
のみの文字を含む有効な名前の多くを排除するために起こっていますか?本当にオライリー氏がサインアップできないようにする必要があります。あなたの正規表現はそれを文字a-zにも限定しているので、Piére自身も運が悪くなります。 – Quentin
その電子メールの正規表現では「いいえ」と表示されます。あまりにも完璧な良いメールアドレスの多くに。 – Quentin
RFC822電子メールの正規表現をキューに入れるhttp://ex-parrot.com/~pdw/Mail-RFC822-Address.html – Jamiec