You are here: irt.org | FAQ | JavaScript | Text | Q348 [ previous next ]
Try something like this:
<SCRIPT language="JavaScript"><!-- function isValid(string,allowed) { for (var i=0; i< string.length; i++) { if (allowed.indexOf(string.charAt(i)) == -1) return false; } return true; } var valid = '0123456789._'; // define valid characters var test = '123'; alert(isValid(test,valid)); // returns true var test = '1x2'; alert(isValid(test,valid)); // returns false //--></SCRIPT>