Solved

Quick Expression Question

Posted on 2009-06-28
3
147 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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