us1975mc
asked on
Regular Expression Validator Validation Control Expression
I need a RegularExpressionValidator to validate a textbox that has only one character. It can have only the letters A-Z, or the numbers 0-9, or a dash, or an apostrophe, or a space. Any ideas what the ValidationExpression is?
Try this;
SubjectString = "121234567890-=\][poiuytrewqq';l/., "
Try
If Regex.IsMatch(SubjectString, "[\w\x20\x27\x2D]") Then
' Successful match
Else
' Match attempt failed
End If
Catch ex As ArgumentException
'Syntax error in the regular expression
End Try
ASKER
SriVaddadi,
I am still able to enter other characters. Below is my code.
I am still able to enter other characters. Below is my code.
<asp:RegularExpressionValidator ID="Regex1"
runat="server"
ErrorMessage="RegularExpressionValidator"
ControlToValidate="Let1"
ValidationExpression="([A-Z]{1,1})|([0-9]{1,1})|(-)|(')|(\S)" >
</asp:RegularExpressionValidator>
ASKER
mgfranz,
I am really lost on this. Do I still need a RegularExpressionValidator ? Where do I place the code? In the Let1_TextChanged?
I am really lost on this. Do I still need a RegularExpressionValidator
Protected Sub Let1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Let1.TextChanged
Dim Subjectstring As String
SubjectString = "121234567890-=\][poiuytrewqq';l/., "
Try
If Regex.IsMatch(SubjectString, "[\w\x20\x27\x2D]") Then
Let2.Focus()
Else
Let1.Focus()
MsgBox("Try Again")
End If
Catch ex As ArgumentException
'Syntax error in the regular expression
End Try
End Sub
If you would rather not use ASCII parameters, you can use this;
SubjectString = "`~1!2@3#4$5%6^7&8*9(0)-_=+qwertyuiop[{]}\|asdfghjkl;:'zxcvbnm,<.>/? "
Try
Dim RegexObj As New Regex("[A-Za-z0-9'\- ]")
If RegexObj.IsMatch(SubjectString) Then
' Successful match
Else
' Match attempt failed
End If
Catch ex As ArgumentException
'Syntax error in the regular expression
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is a solution for what I have ask but I guess I ask the wrong question. I will post another question tomorrow dealing with a different twist.
Thank you for your time and effort.
Thank you for your time and effort.
([A-Z]{1,1})|([0-9]{1,1})|