Solved

Quick Expression Question

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

13 Experts available now in Live!

Get 1:1 Help Now