Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String validation 2

Status
Not open for further replies.

Palmyra

Programmer
Jan 5, 2007
150
US
Can someone point me to how to validate if a user has keyed into a text box in a specific format, for example A1111-11111?

Thanks.
 
Try something like:
Code:
Function StringValid(ByVal sTest As String) As Boolean
   StringValid = sTest Like "?####-#####"
End Function


Regards,
Mike
 
Can I make the validation check for an upper case in the first position?

Thanks
 
Try this:
Code:
Function StringValid(ByVal sTest As String) As Boolean
   StringValid = sTest Like "[A-Z]####-#####"
End Function
Note -- This depends on the Option Compare Binary compiler directive. This is the default. If you have Option Compare Text in your code module, then the Like comparison will not discriminate between upper & lower case.


Regards,
Mike
 
Have been using below and users have been happy. However, now they'd like to force either an upper case letter or a number in the first position (but not a lower case letter). Is that possible?

Thanks.



Function StringValid(ByVal sTest As String) As Boolean
StringValid = sTest Like "[A-Z]####-#####"
End Function
 
StringValid = sTest Like "[0-9A-Z]####-#####"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top