Forum Moderators: open
Hope someone can find the time to help.
Thanks in advance
function checkForChars(fieldValue, fieldName){
var illegalChars = "1234567890";
for (var i = 0; i < fieldValue.length; i++) {
if (illegalChars.indexOf(fieldValue.charAt(i))!= -1) {
alert ("The filename contains illegal characters.);
return false;
}
}
}
function checkForChars(fieldValue, fieldName){
var illegalChars = "1234567890";for (var i = 0; i < fieldValue.length; i++) {
if (illegalChars.indexOf(fieldValue.charAt(i))!= -1) {
alert ("The filename contains illegal characters.);
return false;
}
}
}
this line initializes a string that contains all possible numeric digits:
var illegalChars = "1234567890";
this line iterates on a loop where i goes from 0 to n where n = (number of characters in fieldValue) - 1:
for (var i = 0; i < fieldValue.length; i++) {
this line checks if the ith (charAt(i)) character in fieldValue (fieldValue.charAt(i)) exists in illegalChars (if it exists indexOf returns a positive number indexing to the first occurence, otherwise -1 means it doesn't exist):
if (illegalChars.indexOf(fieldValue.charAt(i))!= -1) {
if checkForChars returns true you have all non-numeric digits in fieldValue.
function checkForChars(fieldValue){
return fieldValue.match( /\d/);
}
That's called a regular expresion, the \d means any numerical character. It'll return null, or false, if there is no numeric characters.
I've also removed the fieldName argument, as it didn't seem to be used.