[RESOLVED] Need help with a simple regex pattern
I need a pattern for an asp.net validator that's for a phone extension field on the entry part of the page. I need it to allow a single digit up to 5 digits. I was able to use this pattern "\d{5}?" until the requirements changed to "up to 5 digits" on me
Anyone care to help with this?
Re: Need help with a simple regex pattern
not sure but something like this?
\[0-9]{5}
Re: Need help with a simple regex pattern
Re: [RESOLVED] Need help with a simple regex pattern
You don't backslash [0-9].
Also, \d and [0-9] are the same thing.
What does the string look like that you will be searching.
Might be easier to help.
I'm not aware of a way to determine a variable amount of letters other than \d+.
However, it depends on what is around that number that can help determine a possible bound for stopping the search for a number.
Re: [RESOLVED] Need help with a simple regex pattern
{5} is for max 5
{0,5} is for a minimum of 1 and a maximum of 5. You didn't mention any thing about minimum? :)
Re: [RESOLVED] Need help with a simple regex pattern
ahh, ok..that's cool good to know there's a variable amount you can search for.
He said "up to 5"...that sounds variable to me. lol
Re: [RESOLVED] Need help with a simple regex pattern
Sorry guys, I guess I posted using too much common sense. I figured that given I said it's for a phone number extension field and it's required to be "up to 5" you guys, as programmers, would know the range is 0 to 5 digits. Each digit being a number >= 0 and <= 9.