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?
[489 byte] By [shipwreck99] at [2007-11-20 11:34:58]
# 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?
shipwreck99 at 2007-11-9 11:54:01 >
# 2 Re: alphabetic character validation
so after this function how do i validate the Form_lastname?
That is what the function does. Although I would make it return the variable IsAlpha that way you can just call it and check the boolean return. If you do that, the following code will produce checkLastName as true or false based on the validation of the last name.

checkLastName = IsAlpha(Form_lastname)
PeejAvery at 2007-11-9 11:55:03 >
# 3 Re: alphabetic character validation
Yeah i did the alphabetic validation. Now i need a function that will validate the a textbox for the following:

* Must be a string value of seven characters with tfirst character being alphabetic & the remaining six being numeric digits. (eg. L234512)

can anyone help? thanks a lot peejavery for helping..
shipwreck99 at 2007-11-9 11:56:02 >
# 4 Re: alphabetic character validation
That can be done in just 3 easy steps.

1. Check the length using Len() to make sure it is 7 characters long.

2. Check the first character with Mid() using the pattern [A-Z]|[a-z]

3. Check last 6 characters with Mid() using the pattern [0-9]
PeejAvery at 2007-11-9 11:57:07 >
# 5 Re: alphabetic character validation
erm...sorry i'm quite newbie in VBScripting. can u tell me how to write the code?
shipwreck99 at 2007-11-9 11:58:08 >
# 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
...
PeejAvery at 2007-11-9 11:59:06 >
# 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?
shipwreck99 at 2007-11-9 12:00:12 >
# 8 Re: alphabetic character validation
My guess is that you are altering a boolean variable among all that jumble. I suggest cleaning the code up. It isn't even indented properly. It would take a lot of time and mind to sort it out.
PeejAvery at 2007-11-9 12:01:15 >