Solved

Quick Expression Question

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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