alphabetic character validation
I'm using VBscript to validate a form in an asp page. I need to validate two textboxes. One for alphabetic character & the other will be alphanumeric(The first letter should be alphabetic & the next 5 should be numeric) how can i do it.
after validating if there is any problem the asp page will redirect the page to the form & if there is no problem it will do an sql query on a database to search for matching results..
Can anyone help me to validate the two textboxes?
# 1 Re: alphabetic character validation
Ok i've got this piece of code that validates alphabetic characters in a form. But i can't figure out what needs to be changed for it to work on my form.
Form_lastname = Trim(Request.Form("lname"))
This is how i get the form input into the validation page. & the validation code is:
<%
Private Function IsAlpha(byVal string)
dim regExp, match, i, spec
For i = 1 to Len( string )
spec = Mid(string, i, 1)
Set regExp = New RegExp
regExp.Global = True
regExp.IgnoreCase = True
regExp.Pattern = "[A-Z]|[a-z]|\s|[_]"
set match = regExp.Execute(spec)
If match.count = 0 then
IsAlpha = False
Exit Function
End If
Set regExp = Nothing
Next
IsAlpha = True
End Function
%>
so after this function how do i validate the Form_lastname?
# 6 Re: alphabetic character validation
Well, it is just pieces of your last code you posted.
1. Check the length using Len() to make sure it is 7 characters long.
If Len(VARIABLE) = 7 then
' it passed so check the patterns.
End If
2. Check the first character with Mid() using the pattern [A-Z]|[a-z]
firstpart = Mid(variable, 1, 1)
Set regExp = New RegExp
regExp.Global = True
regExp.IgnoreCase = True
regExp.Pattern = "[A-Z]|[a-z]"
set match = regExp.Execute(firstpart)
If match.count = 0 then
...
3. Check last 6 characters with Mid() using the pattern [0-9]
secondpart = Mid(variable, 2, 6)
Set regExp = New RegExp
regExp.Global = True
regExp.IgnoreCase = True
regExp.Pattern = "[0-9]"
set match = regExp.Execute(spec)
If match.count = 0 then
...
# 7 Re: alphabetic character validation
ok it does the validation but something is wrong when i put all the three validations together. Here goes the code:
<%
Form_customerid = Trim(Request.Form("custID"))
Form_lastname = Trim(Request.Form("lname"))
Form_ordernumber = Trim(Request.Form("ordernumber"))
%>
<%
Validated_Form = true
'---Customer Name validation--
Private Function IsAlpha(byVal string)
dim regExp, match, i, spec
For i = 1 to Len( string )
spec = Mid(string, i, 1)
Set regExp = New RegExp
regExp.Global = True
regExp.IgnoreCase = True
regExp.Pattern = "[A-Z]|[a-z]|\s|[_]"
set match = regExp.Execute(spec)
If match.count = 0 then
IsAlpha = False
Exit Function
End If
Set regExp = Nothing
Next
IsAlpha = True
End Function
checkLastName = IsAlpha(Form_lastname)
IF checkLastName =True THEN
response.redirect "select.asp"
END IF
IF checkLastName = False THEN
response.redirect "search.asp"
END IF
'-----------
'--order number validation---
If Len(Form_ordernumber) = 7 then
' it passed so check the patterns.
End If
firstpart = Mid(Form_ordernumber, 1, 1)
Set regExp = New RegExp
regExp.Global = True
regExp.IgnoreCase = True
regExp.Pattern = "[A-Z]|[a-z]"
set match = regExp.Execute(firstpart)
If match.count = 0 then
secondpart = Mid(Form_ordernumber, 2, 6)
Set regExp = New RegExp
regExp.Global = True
regExp.IgnoreCase = True
regExp.Pattern = "[0-9]"
set match = regExp.Execute(spec)
If match.count = 0 then
secondpart = false
Else second part = true
END IF
END IF
IF secondpart = false THEN
response.redirect "search.asp"
END IF
IF secondpart = true THEN
response.redirect "select.asp"
END IF
'----------
'--customer ID validation---
IF len(Form_customerid)<0 THEN
Validated_Form = false
END IF
IF IsNumeric(Form_customerid) = false THEN
validated_Form = false
END IF
IF IsNumeric(Form_customerid) THEN
number = int(Form_customerid)
if number < 1000000 and number > 99999 THEN
validated_Form = true
ELSE
validated_Form = false
END IF
END IF
'-----------
IF Validated_Form = false THEN
response.redirect "search.asp"
END IF
IF Validated_Form = true THEN
response.redirect "select.asp"
END IF
%>
Every time it goes through this validation process all the pages goes thorugh to select.asp. So it's not validating anything. But if i do those individually they work just fine. so what is my mistake?