View Full Version : JScript Validation (alpha only)

06-05-2003, 02:56 AM
i am trying to make sure a user posts only valid information. the first and last name fields are giving me trouble. i need to have a script that will validate for <b>no numerical characters</b> in the whole variable using the <b>onblur</b> method. i cannot get this accomplished without getting mulitle errors. what i have is not working in other words.

if anyone has seen it on a site or knows how to validate for it please let me know. thanks in advance! :thumbsup:

06-05-2003, 03:26 AM
don't get confused. an asp file can use javascript in there.

Philip M
06-05-2003, 08:48 AM
This checks for bad characters and also that the name is "sensible".

function checkname(which) {
var badchars='/\@:?%!&$#~<>^*+=";1234567890{}[]'; // invalid characters
var vowels="AaEeIiOoUuYy"; // name must contain at least one vowel: M.H.Byng ok!
var cons=/[^AaEeIiOoUuYy]/; // name must contain at least one consonant: A.A.Lee ok!
var blank="";
var vflag=0;
var bflag=0;
var name=which.value;
for (x=0;x < name.length;x++) {
if (vowels.indexOf(name.charAt(x))!=-1) {vflag=1}
if (badchars.indexOf(name.charAt(x))!=-1) {bflag=1}
if (name.search(cons)==-1) {vflag=0}
if (name.length < 6 || name.length > 24 || vflag==0) {
alert ("That does not appear to be a valid person's name. \nPlease try again.");
if (bflag==1 && vflag==1) {
alert ("Invalid characters were entered into this field.\nOnly alphabetic characters are allowed.\n\nPlease try again.");

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum