473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

help with lastname regex in c# code

dje
Regex regex = new Regex("/[a-zA-Z '-]/");
Match match;
match = regex.Match(this.LastName.Text);
if(!match.Success)
{
sb.Append("Last name invalid. ");
returnValue=false;
}
with the input "jones", match.Success always fails. Is there something
wrong with my regular expression or am I not using Regex correctly?
Thanks.
Nov 16 '05 #1
3 1469

The problem is the the forward slashes.
"/jones/" will cause a match.

Robby

"dje" <de@networld.com> wrote in message
news:d7**************************@posting.google.c om...
Regex regex = new Regex("/[a-zA-Z '-]/");
Match match;
match = regex.Match(this.LastName.Text);
if(!match.Success)
{
sb.Append("Last name invalid. ");
returnValue=false;
}
with the input "jones", match.Success always fails. Is there something
wrong with my regular expression or am I not using Regex correctly?
Thanks.

Nov 16 '05 #2
Regex regex = new Regex("[a-zA-Z '-]+");
"dje" <de@networld.com> wrote in message
news:d7**************************@posting.google.c om...
Regex regex = new Regex("/[a-zA-Z '-]/");
Match match;
match = regex.Match(this.LastName.Text);
if(!match.Success)
{
sb.Append("Last name invalid. ");
returnValue=false;
}
with the input "jones", match.Success always fails. Is there something
wrong with my regular expression or am I not using Regex correctly?
Thanks.

Nov 16 '05 #3
dje
thx Igor and Robby!

"Igor" <no@way.com> wrote in message news:<u4**************@TK2MSFTNGP15.phx.gbl>...
Regex regex = new Regex("[a-zA-Z '-]+");
"dje" <de@networld.com> wrote in message
news:d7**************************@posting.google.c om...
Regex regex = new Regex("/[a-zA-Z '-]/");
Match match;
match = regex.Match(this.LastName.Text);
if(!match.Success)
{
sb.Append("Last name invalid. ");
returnValue=false;
}
with the input "jones", match.Success always fails. Is there something
wrong with my regular expression or am I not using Regex correctly?
Thanks.

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Shi | last post by:
Hello folks, I want to retrieve full name, city name, state and country from following string: "(Firstname Lastname - Traverse City, MI United States)" I think maybe a regex can be a...
3
by: Richard | last post by:
Trying to wrap my brain around Regex for the first time... I need to be able to replace Sql @NamedParameters with "?" for compliance with an extremely lame 3rd party Odbc driver. I know that...
10
by: gonzal51 | last post by:
Hi, I'm a student learning C++ and my professor isn't much help, her view is if you dont get it I ain't helping you.... We are supposed to do a basic program as a logon system. I got as far as I...
3
by: Chris Dunaway | last post by:
I need to find all occurrences of a comma in a string EXCEPT where it occurs between quotation marks. For Example: Field1,Field2,Field3,Fiel4,"Lastname, Firstname",Field5, Field6 So I need...
4
by: pms | last post by:
Need suggestions to improve this program. using System; namespace CalculateWage { class GetEmployeeDetails {
0
by: Riaaaa | last post by:
Hello members, This is the SQL SERVER 2005 stored procedure. It contains the data from the two diff tables. (1)Customer : Here clpid and cardid are composite primary keys with the identity...
2
by: Brad King | last post by:
Hello Everyone, I am having trouble reading a file. My eventual plan is to read in the file, fix a formatting problem with a regex and export the changed data to a new file. However my importing...
3
by: =?Utf-8?B?TmF2ZWVu?= | last post by:
Not sure if this is the right forum for this question but couldn'd find another newsgroup. I am new to Regular expressions and would like help in deciding which pattern allows me to split a...
6
by: mohaaron | last post by:
Hello all, I'm not very good with writing regular expressions and need some help with this one. I need to validate an email address which has the full name of the person appended to the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.