var reqfields = Array("Email::Email", "Firstname::First Name","Lastname::Last Name","month::Birthdate Month","day::Birthdate Day","year::Birthdate Year","Address::Adress","City::City","State::State","Zip::Zip");
function checkIt()
{
var msg = "The Following Information Needs Attention, Please Fix And Resubmit \n\n";
var mssg = "Only letters and numbers are allowed for these fields \n\n";
var str = /^[\w+\d+]/;
for (var i=0; i<reqfields.length; i++)
{
thStuff = reqfields[i].split("::");
thText = thStuff[1];
thName = thStuff[0];
theField = document.g_form[thName];
if (theField.value == "")
msg += thText+" Is REQUIRED \n";
else if(g_form[thName])
{
if(!str.test(document.g_form[thName].value))
msg += thText+" Can Only Have Letters Or Numbers\n";
}
}
if (msg.length>90)
{
alert(msg);
return false;
}
return true;
}
you need to identify which fields can only have numbers or letters and put them in your else if block...otherwise it will check all of them and that obviously won't work for email addresses etc...
Burrito wrote:I wouldn't use that pattern...use the second one I posted.
Then it makes every field wrong / error message out even if i take out the ! from the !str in the if statement, since I need all the fields to accept at least @#,.
var reqfields = Array("Email::Email", "Firstname::First Name", "Lastname::Last Name", "month::Birthdate Month", "day::Birthdate Day", "year::Birthdate Year", "Address::Address", "City::City", "State::State", "Zip::Zip");
function checkIt() {
var msg = "The following fields were either left blank or contained special characters, please fix and resubmit. \n\n";
// var str = /^[\w+\d+]/;
var str = /[^a-zA-Z0-9\s]/;
for (var i = 0; i<reqfields.length; i++) {
thStuff = reqfields[i].split("::");
thText = thStuff[1];
thName = thStuff[0];
theField = document.g_form[thName];
if (theField.value == "") {
msg += thText+" Is REQUIRED \n";
} else if (g_form[thName]) {
if (str.test(document.g_form[thName].value)) {
msg += thText+" Can Only Have Letters Or Numbers\n";
}
}
}
if (msg.length>255) {
alert(msg);
return false;
}
return true;
}
var reqfields = Array("Email::Email", "Firstname::First Name", "Lastname::Last Name", "month::Birthdate Month", "day::Birthdate Day", "year::Birthdate Year", "Address::Address", "City::City", "State::State", "Zip::Zip");
function checkIt() {
var msg = "The following fields were either left blank or contained special characters, please fix and resubmit. \n\n";
// var str = /^[\w+\d+]/;
var str = /[^a-zA-Z0-9\s@#-\.,]/;
for (var i = 0; i<reqfields.length; i++) {
thStuff = reqfields[i].split("::");
thText = thStuff[1];
thName = thStuff[0];
theField = document.g_form[thName];
if (theField.value == "") {
msg += thText+" Is REQUIRED \n";
} else if (g_form[thName]) {
if (str.test(document.g_form[thName].value)) {
msg += thText+" Can Only Have Letters Or Numbers\n";
}
}
}
if (msg.length>255) {
alert(msg);
return false;
}
return true;
}
is still allowing other characters through ( ie ;()*&^%$!~ )