Javascript Tutorial to Validate Indian Voter ID Number Format Using Regular Expression in Browser Full Project For Beginners

 

 

 

index.html

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Validate PAN Card Number in Javascript</title>
</head>
<body>
    <input type="text" name="voter_IDno" class="form-control" onchange="return validateVoterID(this)" placeholder="Enter Voter ID Number" maxlength="10">
<hr />
<input type="button" id="btnSubmit" value="Submit" onclick="ValidatePAN()" />  
</body>
<script type="text/javascript">
  function validateVoterID(ths) {
    var inputvalues = $(ths).val();
    var regex = /^([a-zA-Z]){3}([0-9]){7}?$/g;
    if (!regex.test(inputvalues)) {
        $(ths).val("");
        $(ths).parent().append('<span class="error">Invalid Voter ID Number</span>');
        return regex.test(inputvalues);
    } else {
        $(ths).parent().find(".error").remove();
        return true;
    }
}
</script>
</html>

Leave a Reply