All Forums >> [Scripting] >> ASP >> Checking the first 3 characters Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I'm calling a value from database (numeric column)
Now I want to check the first 3 numbers in that value. And if for eg. first three numbers are 123, I want to do something otherwise not. So whats the syntax for cheking the first 3 numbers?
Posts: 4
Score: 0
Joined: 8/12/2004
From: USA
Status: offline
Just why are you using MID, below is some sample code using the LEFT function which makes more sense. **************
<HTML><HEAD></HEAD> <BODY>
<% IF Request.Form("inputNumber")<>"" THEN %> The number you entered is: <%=Request.Form("inputNumber")%><BR> The first three numbers are: <%=Left(Request.Form("inputNumber"),3)%><BR> <p><A HREF="test.asp">Input another number</A></p> <% ELSE %> <FORM method="post" action="test.asp"> Input a number: <input type="text" name="inputNumber"><br><BR> <input type="submit" value="submit"> </form> <% END IF %>
Posts: 4
Score: 0
Joined: 8/12/2004
From: USA
Status: offline
Oh, almost forgot the decision - to do something if the first three numbers are 123, try the code below - it should be fairly simple to modify the code for your needs :-)
<HTML><HEAD></HEAD> <BODY>
<% IF Request.Form("inputNumber")<>"" THEN %> The number you entered is: <%=Request.Form("inputNumber")%><BR> The first three numbers are: <%=Left(Request.Form("inputNumber"),3)%><BR> <p><A HREF="test.asp">Input another number</A></p>
<% If Left(Request.Form("inputNumber"),3)="123" THEN Response.Write "<h1>The first 3 numbers were 123!</h1>" ELSE Response.Write "<h1>The first 3 numbers were N-O-T 123!</h1>" END IF %>