SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2002
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with form's username validation to contain no spaces and special chars

    Ok, I am (still) trying to validate this form's username and make sure it contains no spaces and no special characters. I've been trying forever now... Can you point me in the right direction or get me out of this hole please?

    This is what I have:

    Code:
      	<script language="javascript" type="text/javascript">	
      		function submitbutton() {
      			var form = document.cmd;
     			var r = new RegExp("[\<|\>|\"|\'|\;|\:|\[|\]|\{|\}|\(|\)|\+|\-|\_|\*|\&|\^|\$|\%|\#|\@|\!|\?|\=|\/|\.|\,]", "i");
      if (r.exec(form.username.value) || form.username.value.length < 3) {
     		 	alert( "Please enter a valid Username: No spaces, No special characters, more than 2 characters and containing numbers and letters only (0-9,a-z,A-Z)" );
      			} else {
      				form.submit();
      			}
      		}
      	</script>
    What do you see wrong?

    I tried adding the \s or \s* modifier in the pattern to match whitespaces ( I tried adding [\s*|\<|\>|\"|\'|\;|\:... ecc and I also tried without the asterisk, but it just doesn't seem to want to match a space!!!

    Thanks for your input! I appreciate your time!

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alert! There's already a thread on this question.

  3. #3
    SitePoint Member mylungsarempty's Avatar
    Join Date
    Feb 2004
    Location
    Wallingford, CT
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •