Solved

Quick Expression Question

Posted on 2009-06-28
3
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

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

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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