Cin validation in javascript

Javascript Code

<script>
$("#cin_no").keypress(function(e){
		var charCode = e.which;
		var name = $("#cin_no").val();

		/*
          8 - (backspace)
          32 - (space)
          48-57 - (0-9)Numbers
        */

		//alert(name);
		if (name.length < 1)
		{
			if(charCode != 108) {
				return false;
			}
		}
		if (name.length >= 1 && name.length < 6)
		{
			if((charCode != 8 || charCode ==32 ) && (charCode < 48 || charCode > 57)) {
				return false;
			}

		}
		if (name.length >= 6 && name.length < 8)
		{
			if(!(charCode >= 65 && charCode <= 90) && !(charCode >= 97 && charCode <= 122) && (charCode != 32 && charCode != 8) && !(charCode == 9)) {
				return false;
			}
		}
		if (name.length >= 8 && name.length < 12)
		{
			if((charCode != 8 || charCode ==32 ) && (charCode < 48 || charCode > 57)) {
				return false;
			}

		}
		if (name.length >= 12 && name.length < 15)
		{
			if(!(charCode >= 65 && charCode <= 90) && !(charCode >= 97 && charCode <= 122) && (charCode != 32 && charCode != 8) && !(charCode == 9)) {
				return false;
			}
		}
		if (name.length >= 15 && name.length < 21)
		{
			if((charCode != 8 || charCode ==32 ) && (charCode < 48 || charCode > 57))
			{
				return false;
			}
		}
		if(name.length > 20){
			return false;
		}
	});
</script>

0 Comments

Leave a Reply

You must be logged in to post a comment.