Alphanumeric with At sign validation in javascript

Javascript Code

<input type="text" name="username" id="username" placeholder="Enter UserName" >
<script>
	$(document).ready(function(){
		$("#username").keypress(function(e){
			var charCode = e.which;
			/*
              8 - (backspace)
              32 - (space)
              64 - (@)
              65-98 - (a-z)Alphabet
              48-57 - (0-9)Numbers
            */
			if(!(charCode >= 65 && charCode <= 90)
					&& !(charCode >= 97 && charCode <= 122)
					&& (charCode != 32 && charCode != 8)
					&& !(charCode == 9) && (charCode < 48 || charCode > 57) && !(charCode == 64)
			 ) {
				return false;
			}
		});
	});
</script>

0 Comments

Leave a Reply

You must be logged in to post a comment.