Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am doing a project that displays the semester wise marks according to the given HallTicket Number. So, i have to provide validation for entered Hall ticket number using javascript. And hall ticket number has following constraints
 
--->It shouid hav exactly 10 characters
--->starting two positions may be 10 or 11 or 12
--->next four positions must be the string "kp1a"
--->later two positions may contains any of 02 or 04 or 05 or 12 only
--->remaing two positions may any digits from 01 to 60.
Can any one say How to write javascript for validating this kind of Hall ticket number.
 
Please help me. thanks in advance.
Posted 22-Jan-13 1:30am
Comments
shabari7 at 22-Jan-13 6:51am
   
better use regular expression
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v2
Comments
shabari7 at 22-Jan-13 7:50am
   
You can make it even simpler,shorter with less code,do it ur self
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<script language="javascript" type="text/javascript">
        function fnValidate() {
            var ticket = document.getElementById("txtTest").value.toLowerCase();
            var status = "";
            var C1 = ticket.substr(0, 2);
            var C2 = ticket.substr(2, 2);
            var C5 = ticket.substr(4, 1)
            var C6 = ticket.substr(5, 1);
            var C3 = ticket.substr(6, 2);
            var C4 = ticket.substr(8, 2);
            if (ticket.length == 10) {
                if (C1 == "10" || C1 == "11" || C1 == "12") {
                    if (C2 == "kp" && parseInt(C5)==1 && C6=="a") {
                        if (parseInt(C3) == 02 || parseInt(C3) == 04 || parseInt(C3) == 05 || parseInt(C3) == 12) {
                            if (C4 > 0 && C4 <= 60) {
                                status = "valid";
                            }
                        }
                    }
                }
            }
            if (status != "") {
                alert("Valid");
            }
            else {
                alert("InValid");
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtTest" runat="server" Height="30px" Width="80px" MaxLength="10"></asp:TextBox><br />
        <asp:Button ID="btnValidate" runat="server" Text="Vaildate" OnClientClick="fnValidate()"/>
    </div>
    </form>
</body>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 Raul Iloc 170
4 Maciej Los 164
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100