473,752 Members | 8,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on Regular Expression

I am new in Regular Expression. Could someone please help me in following
expression?
1. the string cannot be empty
2. the string can only contains AlphaNumeric characters. No space or any
special characters are allowed
3. space characters at the end of string is ok
4. the string cannot contains only numeric characters, in other word, the
string must contains a least one alpha character

Thanks for the help
Nov 21 '05 #1
5 1746
John:

The following code will check for a string that is 1-20 characters long. It
does not specifically test Condition 3 but you could trim the string and then
check it.

Private Function CheckStringRule s(ByVal psString) As _Outcome

Dim lsPattern As String
Dim mc As MatchCollection
Dim m As Match

'Check for allowed character set; the length has to be 1-20
lsPattern = "^([a-zA-Z0-9|]{1,20})$"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of number
lsPattern = "[0-9]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of upper-alpha character
lsPattern = "[A-Z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of lower-alpha character
lsPattern = "[a-z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

Return _Outcome.Succes sful

End Function

"John" wrote:
I am new in Regular Expression. Could someone please help me in following
expression?
1. the string cannot be empty
2. the string can only contains AlphaNumeric characters. No space or any
special characters are allowed
3. space characters at the end of string is ok
4. the string cannot contains only numeric characters, in other word, the
string must contains a least one alpha character

Thanks for the help

Nov 21 '05 #2
Thanks vvenk for your reply.
What I want to do is to add a RegularExpressi onValidator control in the form
and specify a RegularExpressi on for the Validator control and validate
against a textbox in client side.
Is that possible to combine all the requirement into one Regular Expression,
so that I don't need to go to code-behind to do the validation?
Thanks again.
"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:45******** *************** ***********@mic rosoft.com...
John:

The following code will check for a string that is 1-20 characters long. It does not specifically test Condition 3 but you could trim the string and then check it.

Private Function CheckStringRule s(ByVal psString) As _Outcome

Dim lsPattern As String
Dim mc As MatchCollection
Dim m As Match

'Check for allowed character set; the length has to be 1-20
lsPattern = "^([a-zA-Z0-9|]{1,20})$"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of number
lsPattern = "[0-9]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of upper-alpha character
lsPattern = "[A-Z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of lower-alpha character
lsPattern = "[a-z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

Return _Outcome.Succes sful

End Function

"John" wrote:
I am new in Regular Expression. Could someone please help me in following expression?
1. the string cannot be empty
2. the string can only contains AlphaNumeric characters. No space or any
special characters are allowed
3. space characters at the end of string is ok
4. the string cannot contains only numeric characters, in other word, the string must contains a least one alpha character

Thanks for the help

Nov 21 '05 #3
Aren't Regular Expressions powerful ...

(?i)^([a-z]|\d)+((?<=\d)[a-z]|(?<=[a-z]))[a-z0-9]*

case insensitive
start of string
match one or more letters OR one or more digits
continue matching if previous is
one digit followed by one letter
OR
one letter
match zero or more letters and digits

--Robby
"John" <Jo**@hotmail.c om> wrote in message
news:um******** *****@TK2MSFTNG P11.phx.gbl...
Thanks vvenk for your reply.
What I want to do is to add a RegularExpressi onValidator control in the
form
and specify a RegularExpressi on for the Validator control and validate
against a textbox in client side.
Is that possible to combine all the requirement into one Regular
Expression,
so that I don't need to go to code-behind to do the validation?
Thanks again.
"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:45******** *************** ***********@mic rosoft.com...
John:

The following code will check for a string that is 1-20 characters long.

It
does not specifically test Condition 3 but you could trim the string and

then
check it.

Private Function CheckStringRule s(ByVal psString) As _Outcome

Dim lsPattern As String
Dim mc As MatchCollection
Dim m As Match

'Check for allowed character set; the length has to be 1-20
lsPattern = "^([a-zA-Z0-9|]{1,20})$"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of number
lsPattern = "[0-9]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of upper-alpha character
lsPattern = "[A-Z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of lower-alpha character
lsPattern = "[a-z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

Return _Outcome.Succes sful

End Function

"John" wrote:
> I am new in Regular Expression. Could someone please help me in following > expression?
> 1. the string cannot be empty
> 2. the string can only contains AlphaNumeric characters. No space or
> any
> special characters are allowed
> 3. space characters at the end of string is ok
> 4. the string cannot contains only numeric characters, in other word, the > string must contains a least one alpha character
>
> Thanks for the help
>
>
>


Nov 21 '05 #4

opps ... Forgot to check remaining characters are spaces.

(?i)^([a-z]|\d)+((?<=\d)[a-z]|(?<=[a-z]))[a-z0-9]* *$

That is a space between the two *
" *" matches zero or more spaces
$ matches end of string

--Robby

"Robby" <ed****@not.my. email.com> wrote in message
news:u%******** ********@TK2MSF TNGP09.phx.gbl. ..
Aren't Regular Expressions powerful ...

(?i)^([a-z]|\d)+((?<=\d)[a-z]|(?<=[a-z]))[a-z0-9]*

case insensitive
start of string
match one or more letters OR one or more digits
continue matching if previous is
one digit followed by one letter
OR
one letter
match zero or more letters and digits

--Robby
"John" <Jo**@hotmail.c om> wrote in message
news:um******** *****@TK2MSFTNG P11.phx.gbl...
Thanks vvenk for your reply.
What I want to do is to add a RegularExpressi onValidator control in the
form
and specify a RegularExpressi on for the Validator control and validate
against a textbox in client side.
Is that possible to combine all the requirement into one Regular
Expression,
so that I don't need to go to code-behind to do the validation?
Thanks again.
"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:45******** *************** ***********@mic rosoft.com...
John:

The following code will check for a string that is 1-20 characters long.

It
does not specifically test Condition 3 but you could trim the string and

then
check it.

Private Function CheckStringRule s(ByVal psString) As _Outcome

Dim lsPattern As String
Dim mc As MatchCollection
Dim m As Match

'Check for allowed character set; the length has to be 1-20
lsPattern = "^([a-zA-Z0-9|]{1,20})$"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of number
lsPattern = "[0-9]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of upper-alpha character
lsPattern = "[A-Z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of lower-alpha character
lsPattern = "[a-z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

Return _Outcome.Succes sful

End Function

"John" wrote:

> I am new in Regular Expression. Could someone please help me in

following
> expression?
> 1. the string cannot be empty
> 2. the string can only contains AlphaNumeric characters. No space or
> any
> special characters are allowed
> 3. space characters at the end of string is ok
> 4. the string cannot contains only numeric characters, in other word,

the
> string must contains a least one alpha character
>
> Thanks for the help
>
>
>



Nov 21 '05 #5
Robby,
I am really appreciated for your help!

"Robby" <ed****@not.my. email.com> wrote in message
news:OB******** ******@TK2MSFTN GP09.phx.gbl...

opps ... Forgot to check remaining characters are spaces.

(?i)^([a-z]|\d)+((?<=\d)[a-z]|(?<=[a-z]))[a-z0-9]* *$

That is a space between the two *
" *" matches zero or more spaces
$ matches end of string

--Robby

"Robby" <ed****@not.my. email.com> wrote in message
news:u%******** ********@TK2MSF TNGP09.phx.gbl. ..
Aren't Regular Expressions powerful ...

(?i)^([a-z]|\d)+((?<=\d)[a-z]|(?<=[a-z]))[a-z0-9]*

case insensitive
start of string
match one or more letters OR one or more digits
continue matching if previous is
one digit followed by one letter
OR
one letter
match zero or more letters and digits

--Robby
"John" <Jo**@hotmail.c om> wrote in message
news:um******** *****@TK2MSFTNG P11.phx.gbl...
Thanks vvenk for your reply.
What I want to do is to add a RegularExpressi onValidator control in the
form
and specify a RegularExpressi on for the Validator control and validate
against a textbox in client side.
Is that possible to combine all the requirement into one Regular
Expression,
so that I don't need to go to code-behind to do the validation?
Thanks again.
"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:45******** *************** ***********@mic rosoft.com...
John:

The following code will check for a string that is 1-20 characters
long.
It
does not specifically test Condition 3 but you could trim the string
and
then
check it.

Private Function CheckStringRule s(ByVal psString) As _Outcome

Dim lsPattern As String
Dim mc As MatchCollection
Dim m As Match

'Check for allowed character set; the length has to be 1-20
lsPattern = "^([a-zA-Z0-9|]{1,20})$"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of number
lsPattern = "[0-9]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of upper-alpha character
lsPattern = "[A-Z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

'Check for atleast one occurence of lower-alpha character
lsPattern = "[a-z]"
mc = Regex.Matches(p sString, lsPattern)
If mc.Count = 0 Then
Return _Outcome.Failur e
End If

Return _Outcome.Succes sful

End Function

"John" wrote:

> I am new in Regular Expression. Could someone please help me in
following
> expression?
> 1. the string cannot be empty
> 2. the string can only contains AlphaNumeric characters. No space or
> any
> special characters are allowed
> 3. space characters at the end of string is ok
> 4. the string cannot contains only numeric characters, in other word,
the
> string must contains a least one alpha character
>
> Thanks for the help
>
>
>



Nov 21 '05 #6

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

Similar topics

9
3700
by: Steve | last post by:
Hello, I am writing a script that calls a URL and reads the resulting HTML into a function that strips out everthing and returns ONLY the links, this is so that I can build a link index of various pages. I have been programming in PHP for over 2 years now and have never encountered a problem like the one I am having now. To me this seems like it should be just about the simplest thing in the world, but I must admit I'm stumped BIG TIME!...
5
2531
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL, and then reconstruct another URL based on it. For example, I need to scan a web page looking for something like <a href="some_dir/list_20050815100225.csv">. I don't know in advance what the date/time in the file name will be. I need to take the...
4
3229
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no specific format and I have to detect and remove them using a list of strings that may appear as...
6
489
by: JohnSouth | last post by:
Hi I've been using a Regular expression to test for valid email addresses. It looks like: \w+(\w+)*@\w+(\w+)*\.\w+(\w+)* I've now had 2 occassions where it has rejected and email address with a "&" character in the local part. I know I should be able to work it out myself, but I'd like to ask anyone to suggest the best way to
3
2304
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator id="valValidEmail" runat="server" ControlToValidate="txtEmail" ValidationExpression="^(+)(\.+)*@(+)(\.+)*(\.{2,4})$"
1
3718
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
3
2566
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular expression. ^(.+?) uses (?!a spoon)\.$
6
2235
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description: this is a description Slot: slot2
14
2271
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
3
1839
by: Mr.Steskal | last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression Help -------------------------------------------------------------------------------- I need help writing a regular expression that only returns part of a string. For Example I have a multi-line text fragment like below:
0
9031
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8867
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9429
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9383
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8295
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6836
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3354
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 we have to send another system
3
2243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.