Validate Passport number in JavaScript

Last Reply 5 months ago By pandeyism

Posted 5 months 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.

You are viewing reply posted by: pandeyism 5 months ago.
Posted 5 months 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