Link to home
Create AccountLog in
Avatar of rafaelrgl
rafaelrgl

asked on

Prevent user from typing phone number on textbox with multiline

how can i prevent user from typing phone number or any word that repeats the characters like this: aaaa, ..........., bbbbbbbbb.

sometimes the user types like that because i put an rule that force the user to type more then 500 characters.

help on this.
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Use this regular expression to prevent repeated characters:

^(?=.{4,31}$)(?![-.])(?:(?!(.)\1{4})[-.\w])+(?<![-.])$
Avatar of rafaelrgl
rafaelrgl

ASKER

it did not worked as expected:

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 
                                                 ControlToValidate="txtdescription" Display="None" 
                                                 ErrorMessage="&lt;b&gt; Error-  Repeted characters too much." 
                                                 ValidationGroup="uservalidation" ValidationExpression="^(?=.{4,31}$)(?![-.])(?:(?!(.)\1{4})[-.\w])+(?<![-.])$"></asp:RegularExpressionValidator>
                                            <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" 
                                                 runat="server" CssClass="CustomValidatorCalloutStyle" Enabled="True" 
                                                 HighlightCssClass="highlight" PopupPosition="BottomRight" 
                                                 TargetControlID="RegularExpressionValidator2" Width="300px">
                                            </asp:ValidatorCalloutExtender>

Open in new window

What happened?
it worked, sorry, it was my mistake. what about phonenumbers, can i check for that too, and also can i check for url's so i can block those too.
well, i test again, and it's really not working:

enter:

i love this car a lots, i just want to drive

it's not valid this input above, why? i should pass.
sorry i don't understand... what is wrong with "i love this car a lots, i just want to drive"... you said "i should pass".  sorry this makes no sense to me
i mean, it's saying there is repetitive characters on this sentence. So it should pass the regular expression ^(?=.{4,31}$)(?![-.])(?:(?!(.)\1{4})[-.\w])+(?<![-.])$

but it's blocking this sentence.
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer