473,382 Members | 1,348 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,382 software developers and data experts.

Regular Expression Help

Hi everyone. I have never worked with regular expressions
before and here is my dillema:

I have a textbox that I want to only accept this type of
input:

1,2,3-8,10,16 ( Comma separated numbers or Hyphenated
ranges )

I want to use a validator for this, so I assume I use a
regularexpressionvalidator?? If so any help on what I
would write for a regular expression?? Thank you
Jorell
Nov 17 '05 #1
3 4061
Well, you can interrogate it on a number of levels - it really depends on
how thoroughly you want to make your validation.

I mean, you could validate the characters themselves:

^[0-9\-,]*$

What this means: you will have zero or more of the characters 0 through 9, a
dash, or a comma. This would filter out any other character, however, you
would then approve the string ,-,,-,,-9-,,

If you want to get a little bit closer, here is a better regex:

^([0-9]+(\-[0-9]+)*,*)+$

Now, you are required to have one or more numbers, followed by zero or more
instances of a dash followed by one or more numbers, followed by zero or
more instances of a comma - this entire sequence being repeated one or more
times.

Now, you will match 1,2-9,13. You also guarantee that you will get at least
one number put in. However, this doesn't prevent you from putting in 9-2,
which may throw your parser off. It will also validate 0-2-4.

So, you have to sit and play with exactly what you will allow, and gradually
keep expanding what you are doing until you have a great validation in place
that covers every instance that you can come up with.

If your parser is very particular about how the input comes in, then you may
want to write a custom validator in code.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
"Jorell" <zw******@nospam.powervisionsw.com> wrote in message
news:02****************************@phx.gbl...
Hi everyone. I have never worked with regular expressions
before and here is my dillema:

I have a textbox that I want to only accept this type of
input:

1,2,3-8,10,16 ( Comma separated numbers or Hyphenated
ranges )

I want to use a validator for this, so I assume I use a
regularexpressionvalidator?? If so any help on what I
would write for a regular expression?? Thank you
Jorell

Nov 17 '05 #2
Thank you very much!!! Do you happen to know where a
person can learn a little more about creating those??
Thanks in advance!!

Jorell

-----Original Message-----
Well, you can interrogate it on a number of levels - it really depends onhow thoroughly you want to make your validation.

I mean, you could validate the characters themselves:

^[0-9\-,]*$

What this means: you will have zero or more of the characters 0 through 9, adash, or a comma. This would filter out any other character, however, youwould then approve the string ,-,,-,,-9-,,

If you want to get a little bit closer, here is a better regex:
^([0-9]+(\-[0-9]+)*,*)+$

Now, you are required to have one or more numbers, followed by zero or moreinstances of a dash followed by one or more numbers, followed by zero ormore instances of a comma - this entire sequence being repeated one or moretimes.

Now, you will match 1,2-9,13. You also guarantee that you will get at leastone number put in. However, this doesn't prevent you from putting in 9-2,which may throw your parser off. It will also validate 0- 2-4.
So, you have to sit and play with exactly what you will allow, and graduallykeep expanding what you are doing until you have a great validation in placethat covers every instance that you can come up with.

If your parser is very particular about how the input comes in, then you maywant to write a custom validator in code.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
"Jorell" <zw******@nospam.powervisionsw.com> wrote in messagenews:02****************************@phx.gbl...
Hi everyone. I have never worked with regular expressions before and here is my dillema:

I have a textbox that I want to only accept this type of
input:

1,2,3-8,10,16 ( Comma separated numbers or Hyphenated
ranges )

I want to use a validator for this, so I assume I use a
regularexpressionvalidator?? If so any help on what I
would write for a regular expression?? Thank you
Jorell

.

Nov 17 '05 #3
Here are a couple articles to help you get going.

Look closely at the EvaluationFunction attribute and the EvaluateIsValid
method (or function)

http://www.codeproject.com/useritems/DateValidator.asp

http://www.c-sharpcorner.com/Code/20...mValidator.asp

HTH,

bill

"Jorell" <zw******@nospam.powervisionsw.com> wrote in message
news:02****************************@phx.gbl...
Thank you very much!!! Do you happen to know where a
person can learn a little more about creating those??
Thanks in advance!!

Jorell

-----Original Message-----
Well, you can interrogate it on a number of levels - it

really depends on
how thoroughly you want to make your validation.

I mean, you could validate the characters themselves:

^[0-9\-,]*$

What this means: you will have zero or more of the

characters 0 through 9, a
dash, or a comma. This would filter out any other

character, however, you
would then approve the string ,-,,-,,-9-,,

If you want to get a little bit closer, here is a better

regex:

^([0-9]+(\-[0-9]+)*,*)+$

Now, you are required to have one or more numbers,

followed by zero or more
instances of a dash followed by one or more numbers,

followed by zero or
more instances of a comma - this entire sequence being

repeated one or more
times.

Now, you will match 1,2-9,13. You also guarantee that you

will get at least
one number put in. However, this doesn't prevent you from

putting in 9-2,
which may throw your parser off. It will also validate 0-

2-4.

So, you have to sit and play with exactly what you will

allow, and gradually
keep expanding what you are doing until you have a great

validation in place
that covers every instance that you can come up with.

If your parser is very particular about how the input

comes in, then you may
want to write a custom validator in code.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
"Jorell" <zw******@nospam.powervisionsw.com> wrote in

message
news:02****************************@phx.gbl...
Hi everyone. I have never worked with regular expressions before and here is my dillema:

I have a textbox that I want to only accept this type of
input:

1,2,3-8,10,16 ( Comma separated numbers or Hyphenated
ranges )

I want to use a validator for this, so I assume I use a
regularexpressionvalidator?? If so any help on what I
would write for a regular expression?? Thank you
Jorell

.

Nov 17 '05 #4

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

Similar topics

5
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,...
4
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...
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
3
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...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
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...
18
by: Lit | last post by:
Hi, I am looking for a Regular expression for a password for my RegExp ValidationControl Requirements are, At least 8 characters long. At least one digit At least one upper case character
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.