Hey thanks for that! It actually takes care of all my scenarios.Quote:
Originally Posted by gigemboy
Appreciate it!
Printable View
Hey thanks for that! It actually takes care of all my scenarios.Quote:
Originally Posted by gigemboy
Appreciate it!
I am NOT good with Regex expressions. I need 3 RegEx expressions.
1. Is a value in a textbox empty?
2. Is a value in a textbox a number?
3. Is a value in a textbox only alpha characters?
Thanks
Hello,
Do you really need to use RegEx? Couldn't you just do for the first two at least:
vb.net Code:
If Me.TextBox1.Text = String.Empty If IsNumeric(Me.TextBox1.Text)
Thanks but yes I DO need to use RegEx.
1. ^(.*)$
2. ^([0-9]+)$
3. ^([a-zA-Z]+)$
1. ^(.*)$ Does not work
2. ^([0-9]+)$ Works...thanks
3. ^([a-zA-Z]+)$ Does not work
This one ?
Code:Dim regx As Regex
Dim regp As Match
regx = New Regex("\s") 'Matches any whitespace character (including spaces, newlines, tabs, and so on)
regp = regx.Match(TextBox1.Text)
'Console.WriteLine("Emptystring" & regp.Length.ToString)
regx = New Regex("[1-9]")
regp = regx.Match(TextBox1.Text)
'Console.WriteLine("Numbers" & regp.Length.ToString)
regx = New Regex("[Aa-zZ]")
regp = regx.Match(TextBox1.Text)
'Console.WriteLine("Charaters" & regp.Length.ToString)
For the first one if I type " sdfsdf", I need it to come back false because there are other characters there.Quote:
Originally Posted by danasegarane
This one is wrong [1-9] cause if I type gghh123 it comes back True when it is obviously NOT a number.Quote:
Originally Posted by danasegarane
Do you want to combine all these conditons ?
and this one is wrong [Aa-zZ] cause if I type gghh123 it comes back True when it is not all alpha characters.
Well, let's just get them to work separately first.Quote:
Originally Posted by danasegarane
#3 seems to work for me.Quote:
Originally Posted by jesus4u
Post your code.Quote:
Originally Posted by jesus4u
My mistake #3 DOES work. ThanksQuote:
Originally Posted by nmadd
Quote:
Originally Posted by penagate
Look at the regp.Success property and you will see it is True.Code:Sub Main()
Dim s As String = "gghh123 "
Dim regx As Regex
Dim regp As Match
regx = New Regex("[Aa-zZ]")
regp = regx.Match(s)
Aa-zZ is not the same as a-zA-Z. The latter matches alphabetical characters regardless of case, by specifying two ranges; whereas I'm not entirely sure what the former matches—probably everything, or at least a large subset of the ASCII table.
Note that you can also specify case-insensitivity using a flag, which is an optional parameter of the Regex constructor..
The Regex man strikes back.... should handle all three cases...
vb Code:
Dim s As String = "" Dim Pattern As String = "^[\d]*$|^[a-zA-Z]*$|^[\s]{0}$" If System.Text.RegularExpressions.Regex.IsMatch(s, Pattern) = True Then MessageBox.Show("Match!") Else MessageBox.Show("No Match!") End If