Jump to content

[SOLVED] RegExp Help


sawade

Recommended Posts

I have gone through the W3C section on RegExp, and am still not understanding the snytax.

 

I have a code that allows for letters, numbers, and underscores.  However, I want to modify it to only allow letters and nothing else.

 

function validateFirstname(fld) {
   			var error = "";
    		var illegalChars = /\W/; // allow letters, numbers, and underscores

    		if (fld.value == "") {
        		fld.style.background = 'Yellow'; 
        		error = "You didn't enter your FIRST NAME.\n";
    		} else if ((fld.value.length < 3) || (fld.value.length > 30)) {
        		fld.style.background = 'Yellow'; 
        		error = "FIRST NAME is the wrong length.\n";
    		} else if (illegalChars.test(fld.value)) {
        		fld.style.background = 'Yellow'; 
        		error = "FIRST NAME contains illegal characters.\n";
    		} else {
        		fld.style.background = 'White';
    		}
    	return error;
	}

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/173802-solved-regexp-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.