JavaScript Program to Check AADHAAR Card Format Using Regular Expression

Write a JavaScript program to check aadhaar card format using regular expression.

Write a webpage that accepts Username and Aadhaar card as input texts. When the user enters Aadhaar card number ,the JavaScript validates card number and displays whether card number is valid or not. (Assume valid Aadhaar card format to be nnnn.nnnn.nnnn or nnnn-nnnn-nnnn).

Source Code
    <title>Regular expression - Check Aadhar card format</title>
    function check()
        var card_no = document.getElementById('card_no').value
        var re1 = /^\d{4}\.\d{4}\.\d{4}$/
        var re2 = /^\d{4}\-\d{4}\-\d{4}$/

        var res = re1.test(card_no) || re2.test(card_no)
            alert('Card no. is valid.')
            alert('Card no. is not valid.')			
Enter Username <input type="text" id="user_name"/><br>
Enter AADHAR card no. <input type="text" id="card_no"/><br>
<input type="button" value="Submit" onclick="check()"/>

"Coding Hub - Learn to code" app now available on Google Play Store