This post how to validate an email ID, GST Number, Bank IFSC Code, PAN Number with Javascript or jQuery.
Here is a Javascript function to validate the email ID, you need to add the class “email” in the text control.
Code
<script type="text/javascript">
$(document).ready(function () {
$(".email").change(function () {
var inputvalues = $(this).val();
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(inputvalues)){
alert("invalid email id");
return regex.test(inputvalues);
}
});
});
</script>
Html input type text
Email : <input type="text" class="email" >
You need to apply the “gst” class to control and add the below Javascript function.
GST no sample : 05ABDCE1234F1Z2
Code
<script type="text/javascript">
$(document).ready(function () {
$(".gst").change(function () {
var inputvalues = $(this).val();
var gstinformat = new RegExp('^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]1}[1-9A-Z]{1}Z[0-9A-Z]{1}$');
if (gstinformat.test(inputvalues)) {
return true;
} else {
alert('Please Enter Valid GSTIN Number');
$(".gst").val('');
$(".gst").focus();
}
});
});
</script>
ASP Textbox
<asp:TextBox ID="txtGST" MaxLength="15" runat="server" class="gst form-control mandatory" ClientIDMode="Static" placeholder="GST Reg No."></asp:TextBox>
Html input type text
<input type="text" class="gst" >
Here is a validation code for a bank IFSC code.
IFSC code format:
Code
<script type="text/javascript">
$(document).ready(function(){
$(".ifsc").change(function () {
var inputvalues = $(this).val();
var reg = /[A-Z|a-z]{4}[0][a-zA-Z0-9]{6}$/;
if (inputvalues.match(reg)) {
return true;
}
else {
$(".ifsc").val("");
alert("You entered invalid IFSC code");
//document.getElementById("txtifsc").focus();
return false;
}
});
});
</script>
IFSC : <input type="text" class="ifsc">
This post shows the code to validate a PAN number. Here is the Javascript code, just add the class “pan” in a text control.
PAN no. sample: ABCDE1234F
<script type="text/javascript">
$(document).ready(function(){
$(".pan").change(function () {
var inputvalues = $(this).val();
var regex = /[A-Z]{5}[0-9]{4}[A-Z]{1}$/;
if(!regex.test(inputvalues)){
$(".pan").val("");
alert("invalid PAN no");
return regex.test(inputvalues);
}
});
});
</script>
PAN : <input type="text" class="pan">
Thank you for reading! I hope this tutorial will surely help and you if you liked this tutorial, please consider sharing it with others.
You may also like: How to Validate an IP address using Javascript.
You may also like: How to Validate Phone Number with Javascript.
#javascript #jQuery #validation #tutorial #developer