checking usn in javascript

Solutions on MaxInterview for checking usn in javascript by the best coders in the world

showing results for - "checking usn in javascript"
Niclas
19 Nov 2018
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE html>
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head> <title>2a.html</title> </head>
5  <body>
6    <h1>USN validation</h1>
7    <script type="text/javascript">
8    function validate(usn)
9      {
10          var error="";
11
12          var pattern=/^[1-4][A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{3}$/;
13
14          if (!usn.value.match(pattern))
15             {
16                error = "USN is invalid!";
17             }
18
19          if (error.length == 0)
20             alert("USN is valid!");
21          else
22             alert(error);
23      }
24    </script>
25    <form>
26        USN: <input type="text" id="usn"/> <input type="submit" value="SUBMIT" onclick="validate(usn)"/>
27    </form>
28  </body>
29</html>
30