I have tried two functions for testing that a string only have alphanumeric chars…
http://mayacove.com/dev/val/test_validation.html
but neither one of them works…
I if I put a string like “*********” it doesn’t return false…
thank you…
I have tried two functions for testing that a string only have alphanumeric chars…
http://mayacove.com/dev/val/test_validation.html
but neither one of them works…
I if I put a string like “*********” it doesn’t return false…
thank you…
try
function isAlphaNumeric(inpStr){
var validChars = /[a-zA-Z0-9]/;
for(var i=0; i < inpStr.length; i=i+1) {
if(!validChars.test(inpStr.charAt(i))) {
return false;
}
}
//at this point all characters are valid
return true;
}
thank you very very much, this worked… but I just realized I need one more thing:
I need it to accept spaces (like for “New York”, “Mary Jane”, etc…)
how do I do the regex so it accept spaces? thank you very much…
Just include a space in the list of valid chars.
var validChars = /[a-z A-Z0-9]/;
great… thank you very much…
am getting error:
‘length’ is null or not an object…
???
(this was sent from QA person, he sent a screenshot showing JS error in IE; I have not been able to reproduce it myself, in either FF or IE… what could this be?)
thank you…
It would help if you post the code they are using.
the error is thrown by “length” in this function:
function isAlphaNumeric(inpStr){
var validChars = /[a-zA-Z0-9]/;
for(var i=0; i < inpStr.length; i=i+1) {
if(!validChars.test(inpStr.charAt(i))) {
return false;
}
}
//at this point all characters are valid
return true;
}
actually right now I WAS able to reproduce in IE; and line no. of file cited in error console corresponds exactly where in my validation.js is the error… AND the error occurs only in IE, not FF…
can you pls see if you get an error in IE… I just walked over to his machine, this file http://mayacove.com/dev/val/test_validation.html
throws an error in his IE, but not in mine… (when you hit ‘submit’ – that’s when the function is called…) thank you…
???
ok, here is entire form
http://mayacove.com/dev/val/test_validation2.html
in IE, fill in just the first three or four fields (up to “address”), then hit submit, at that point the error occurs… in IE "obj doesn’t support this property or method; in FF, error console it says: “input#lname”.val is not a function… thrown by this line:
if ($(‘input#fname’).val() != ‘’ && !isAlphaNum($(‘input#fname’).val()) ) { return false; }
not even sure it has to do w/this alphanumeric function anymore…
js is here, http://mayacove.com/dev/val/js/val.js,
thank you very much…
oh brother… never mind… I got it… so sorry… thank you…