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:


  	<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!

Alert! There’s already a thread on this question.

where?