473,513 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegEx Help

slg
Gurus,
I am new to RegEx. How can i validate following.
All characters in my strings are [A-Za-z0-9] and underscore

The string MUST begin with Upper Or lowercase character.
Maximum length is 51
can have underscores in between but no spaces any where
cannot end with underscore
Valid
=======
John_Smith
John
JOHN
J129
J129_89
J129_89_aBC

Invalid
=========
J__33 == has two underscores continuously
J__33_ == ends with underscore

TIA

Nov 6 '07 #1
2 1596
Gurus, I am new to RegEx. How can i validate following. All characters
in my strings are [A-Za-z0-9] and underscore

The string MUST begin with Upper Or lowercase character.
Maximum length is 51
can have underscores in between but no spaces any where
cannot end with underscore
Valid
=======
John_Smith
John
JOHN
J129
J129_89
J129_89_aBC
Invalid
=========
J__33 == has two underscores continuously
J__33_ == ends with underscore
TIA
How about:
^[A-Za-z][A-Za-z0-9]*(_[A-Za-z0-9]+)*$

That should take care of everything but the length requirement. You may be
able to get that working as well, using something like

^[A-Za-z]([A-Za-z0-9]|(_(?=[A-Za-z0-9])){0,50}$

but that is a bit more tricky.

Note: I haven't tested these!
Nov 6 '07 #2
Hello slg,

Not that hard is it?

[A-Za-z](_?[A-Za-z0-9])*

guessing that a one character sting is Ok as well. if not, make the * at
the end a +.

Checking for a strings length is something that String.Lentgh was designed
for. Or where you can use the MaxLength of a textbox.

Jesse
Gurus, I am new to RegEx. How can i validate following. All characters
in my strings are [A-Za-z0-9] and underscore

The string MUST begin with Upper Or lowercase character.
Maximum length is 51
can have underscores in between but no spaces any where
cannot end with underscore
Valid
=======
John_Smith
John
JOHN
J129
J129_89
J129_89_aBC
Invalid
=========
J__33 == has two underscores continuously
J__33_ == ends with underscore
TIA
--
Jesse Houwing
jesse.houwing at sogeti.nl
Nov 6 '07 #3

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

Similar topics

6
4775
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
20
8027
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
17
3941
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
2219
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
2072
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
4
2622
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
7
2566
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
4191
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
12140
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
1614
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
7260
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
7384
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
7539
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...
1
7101
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
7525
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...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.