asp validation HELP!

S

skc

<% 'beginning of the form %>
<% '--------------------- %>
<% 'do a length check on the custrefno %>
<% lengthofcustrefno=Len(Request.Form
("CustRefNo")) %>
<% '------------------------------------------
----- %>
<% 'now do a check on the opening digits %>
<% '1digitsleft=Mid(Request.Form
("CustRefNo"),1,1) %>
<% '2digitsleft=Mid(Request.Form("CustRefNo")
1,2) %>
<% '3digitsleft=Mid(Request.Form("CustRefNo")
1,3) %>
<% If Left(Request.Form("CustRefNo"),1)
<>"a" And Len(Request.Form("CustRefNo"))<=10 And Left
(Request.Form("CustRefNo"),3)<>100 Then
If Len
(Request.Form("CustRefNo")) = 1 Then

custreftosave="000000000"&Request.Form
("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 2 Then

custreftosave="00000000"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 3 Then

custreftosave="0000000"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 4 Then

custreftosave="000000"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 5 Then

custreftosave="00000"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 6 Then

custreftosave="0000"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 7 Then

custreftosave="000"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 8 Then

custreftosave="00"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 9 Then

custreftosave="0"&Request.Form("CustRefNo")
End If
If Len
(Request.Form("CustRefNo")) = 10 Then

custreftosave=""&Request.Form("CustRefNo")
End If

End If %>
<% If Left(Request.Form
("CustRefNo"),1)="a" And Len(Request.Form("CustRefNo"))
<=7 And Left(Request.Form("CustRefNo"),3)<>100 Then

onenumberofchars=Len(Request.Form("CustRefNo"))

onenumberofcharswithnoa=(onenumberofchars-1)

onestrippedouta=Mid(Request.Form
("CustRefNo"),2,onenumberofcharswithnoa)
'---------
----------------------------------------------------------
----
If
numberofcharswithnoa = 1 Then

custreftosave="A"&"00000"&onestrippedouta
End If
If
numberofcharswithnoa = 2 Then

custreftosave="A"&"0000"&onestrippedouta
End If
If
numberofcharswithnoa = 3 Then

custreftosave="A"&"000"&onestrippedouta
End If
If
numberofcharswithnoa = 4 Then

custreftosave="A"&"00"&onestrippedouta
End If
If
numberofcharswithnoa = 5 Then

custreftosave="A"&"0"&onestrippedouta
End If
If
numberofcharswithnoa = 6 Then

custreftosave="A"&onestrippedouta
End If
End If %>
<% If Left(Request.Form
("CustRefNo"),1)<>"a" And Len(Request.Form("CustRefNo"))
<=10 And Left(Request.Form("CustRefNo"),3)=100 Then
numberofchars=Len
(Request.Form("CustRefNo"))

numberofcharswithno100=(numberofchars-1)

strippedouta=Mid(Request.Form
("CustRefNo"),4,numberofcharswithno100)
If
numberofcharswithno100 = 1 Then

custreftosave="100"&"000000000"&strippedouta
End If
If
numberofcharswithno100 = 2 Then

custreftosave="100"&"00000000"&strippedouta
End If
If
numberofcharswithno100 = 3 Then

custreftosave="100"&"0000000"&strippedouta
End If
If
numberofcharswithno100 = 4 Then

custreftosave="100"&"000000"&strippedouta
End If
If
numberofcharswithno100 = 5 Then

custreftosave="100"&"00000"&strippedouta
End If
If
numberofcharswithno100 = 6 Then

custreftosave="100"&"0000"&strippedouta
End If
If
numberofcharswithno100 = 7 Then

custreftosave="100"&"000"&strippedouta
End If
If
numberofcharswithno100 = 8 Then

custreftosave="100"&"00"&strippedouta
End If
If
numberofcharswithno100 = 9 Then

custreftosave="100"&"0"&strippedouta
End If
If
numberofcharswithno100 = 10 Then

custreftosave="100"&strippedouta
End If
End If %>

The code above refers to validating numbers for the
following formats:

1.
--
If a number is less than 10 digits long then it is padded
with zeros

2.
--
If a number begins with a 'A' then it must have 6 digits
after it. If <6 digits then pad with zeros, so A1 is
A000001

3.
--
If a number begins with '100' then it must be 13 digits
in length, otherwise pad any numbers out with zeros.

I am having trouble with my validation script above as it
does not process the A number ones!

Please can someone help.

Thanks.

skc
 
J

Jim Buyens

Good grief. Please try this page and see if it does what
you want:

<html>
<head>
<title>Cust Ref No Test</title>
</head>
<body>
<form method="POST" >
<p>You entered: <%
crno = trim("" & Request.Form("CustRefNo"))
response.write crno
if ucase(left(crno,1)) = "A" then
crno = "A" & right("X000000" & mid(crno,2), 6)
else
if left(crno,3) = "100" then
crno = right("X0000000000000" & crno, 13)
else
crno = right("X0000000000" & crno, 10)
end if
end if
%></p>
<p><input type="text" name="CustRefNo"
value="<%=crno%>"></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</html>

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top