Regex - specify a max. length?
-
Hi, I have regular expression for a phone number. The rules i want are; 10 and only 10 digits and any characters in between. eg. "0123456789" "(01)23456789" "(01)23 456 789 "0123 456 789 "0 1 2 3 4 5 6 7 8 9" "01 23 45 67 89" are all acceptable the regex i have is: "([^0-9]{0,}[0-9][^0-9]{0,}){10}" everything works ok except for detecting numbers that are too long (i.e. more than ten characters). I already have a work-around for this, i am just interested to know how to achieve the same thing in a regex. cheers to you.
-
Hi, I have regular expression for a phone number. The rules i want are; 10 and only 10 digits and any characters in between. eg. "0123456789" "(01)23456789" "(01)23 456 789 "0123 456 789 "0 1 2 3 4 5 6 7 8 9" "01 23 45 67 89" are all acceptable the regex i have is: "([^0-9]{0,}[0-9][^0-9]{0,}){10}" everything works ok except for detecting numbers that are too long (i.e. more than ten characters). I already have a work-around for this, i am just interested to know how to achieve the same thing in a regex. cheers to you.
handle keypress event count the pressed in chars. if =10 e.Handled = true. Hope this helps cheers, geri
-
handle keypress event count the pressed in chars. if =10 e.Handled = true. Hope this helps cheers, geri
so I would do sg like
int count=0; if(Char.IsNumber(e.KeyChar)) { count++; } if(count==10) e.Handled=true; //no more chars allowed to be preesed in.
& count-- if user deletes.....(so presses like: e.KeyChar = '\u0008' >> backspace, i guess ) geri -- modified at 2:46 Thursday 29th November, 2007 -
so I would do sg like
int count=0; if(Char.IsNumber(e.KeyChar)) { count++; } if(count==10) e.Handled=true; //no more chars allowed to be preesed in.
& count-- if user deletes.....(so presses like: e.KeyChar = '\u0008' >> backspace, i guess ) geri -- modified at 2:46 Thursday 29th November, 2007Hi, thanks for the reply, but my question was specifically to do with regular expressions. thanks anyway.
-
Hi, I have regular expression for a phone number. The rules i want are; 10 and only 10 digits and any characters in between. eg. "0123456789" "(01)23456789" "(01)23 456 789 "0123 456 789 "0 1 2 3 4 5 6 7 8 9" "01 23 45 67 89" are all acceptable the regex i have is: "([^0-9]{0,}[0-9][^0-9]{0,}){10}" everything works ok except for detecting numbers that are too long (i.e. more than ten characters). I already have a work-around for this, i am just interested to know how to achieve the same thing in a regex. cheers to you.
-
This would have no effect, the beginning is not limited. "^([^0-9]{0,}[0-9][^0-9]{0,}){10}$" fixes this. (in your regex, the number 12345678901 would have caused the underlined part to match.
-
This would have no effect, the beginning is not limited. "^([^0-9]{0,}[0-9][^0-9]{0,}){10}$" fixes this. (in your regex, the number 12345678901 would have caused the underlined part to match.
-
This would have no effect, the beginning is not limited. "^([^0-9]{0,}[0-9][^0-9]{0,}){10}$" fixes this. (in your regex, the number 12345678901 would have caused the underlined part to match.
Thanks, that works just as i need it. I had tried the $ character at the end, but not in conjunction with ^. Thanks to Mabo42 to the reply as well.