Solved

Quick Expression Question

Posted on 2009-06-28
3
144 Views
Last Modified: 2012-05-07
I am not really too up to speed on RegEx expressions but this should be pretty simple.

Basicaly, I have a textbox and I need the RegEx to INSURE there is a SPACE.  So, basically this would be incorrect:

"johndoe"

BUT THIS WOULD BE CORRECT

"john doe"

Trying to insure the user puts a space between their first and last name.
0
Comment
Question by:chrisryhal
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 24731592
[a-z]+ [a-z]+
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 24731869
Hi chrisryhal;

' Regex pattern. Either one of the two following regex patterns will work. In the first pattern the meta
' characters (?i) at the beginning mean that the string is case insensitive. In the second pattern you
' explicitly say that it is case insensitive by repeating the sequence with caps.  
Dim pattern As String = "(?i)[a-z]+\s[a-z]+"
'Dim pattern As String = "[a-zA-Z]+\s[a-zA-Z]+"

' The following test to see if there is two words if not it will dispplay the message.
If Not Regex.IsMatch(TextBox1.Text.Trim, pattern) Then
    MessageBox.Show("TextBox does NOT contain two words. Have user correct it.")
End If

Fernando
0
 
LVL 2

Author Closing Comment

by:chrisryhal
ID: 31597694
Both worked.  Thanks for the help!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now