Gstin validation in javascript
Javascript Code
<script>
$("#gstin_no").keypress(function(e){
var charCode = e.which;
var name = $("#gstin_no").val();
/*
8 - (backspace)
32 - (space)
48-57 - (0-9)Numbers
*/
//alert(name);
if (name.length <= 1)
{
if((charCode != 8 || charCode ==32 ) && (charCode < 48 || charCode > 57)) {
return false;
}
}
if (name.length > 1 && name.length < 7)
{
if(!(charCode >= 65 && charCode <= 90) && !(charCode >= 97 && charCode <= 122) && (charCode != 32 && charCode != 8) && !(charCode == 9)) {
return false;
}
}
if (name.length > 6 && name.length < 11)
{
if((charCode != 8 || charCode ==32 ) && (charCode < 48 || charCode > 57)) {
return false;
}
}
if (name.length == 11)
{
if(!(charCode >= 65 && charCode <= 90) && !(charCode >= 97 && charCode <= 122) && (charCode != 32 && charCode != 8) && !(charCode == 9)) {
return false;
}
}
if (name.length == 12)
{
if((charCode != 8 || charCode ==32 ) && (charCode < 48 || charCode > 57)) {
return false;
}
}
if (name.length == 13)
{
if(!(charCode >= 65 && charCode <= 90) && !(charCode >= 97 && charCode <= 122) && (charCode != 32 && charCode != 8) && !(charCode == 9)) {
return false;
}
}
if(name.length > 14){
return false;
}
});
</script>
0 Comments