Validate Passport number in JavaScript

Last Reply one month ago By pandeyism

Posted one month ago

Hi!

How I can validate for check passport code. For example A3065731

programm must check input data first symbol always be letter not be number and other symbol must be number when input letter then show message error.

Posted one month ago

Hi PRA,

Please refer below sample.

HTML

Passport:
<input name="txtPassport" type="text" id="txtPassport" maxlength="8" />
<input type="submit" value="Submit" onclick="return Check();" />
<script type="text/javascript">
    function Check() {
        var patt = new RegExp("^([A-Z a-z]){1}([0-9]){7}$")
        var advalue = document.getElementById("txtPassport").value;
        if (patt.test(advalue)) {
            return true;
        }
        else {
            alert("Passport is not valid");
        }
        return false;
    }
</script>

Demo