I'm trying to validate an input field to see if the value entered contains a number or the letters X or Y at the start of the string:
var t_index_array = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'X', 'Y'];
for(var i=0, l=t_index_array.length; i < l; i++){
if (document.form.topography_index.value.toUpperCase().substr(0,1) != t_index_array[i]){
alert ( "The Topography index field needs to start with a number between 0 and 9 or the letters X or Y." );
valid = false;
return valid;
}
}
This isn't working as the value of t_index_array[i] is always 0. Any ideas?