I have this textBox control <asp:TextBox ID="txtInformerPhone" runat="server" />
This input is a telephone number and has the following restrictions.
A valid phone number must have the following requirements. First part of the phone number is either 2 figures or 3 figures or 4 figures. The second part is
either 5 figures or 6 figures or 7 figures or 8 figures or 9 figures.
So the user can enter for example 123-12345
This is valid because the first part containd 3 figures which is valid the second part contains 5 figures which is also valid.
Note the user must also enter this character - that is located between the first part and the second part.
I just wonder is it possible to use MaskedEditExtender for this testBox when I have this requirements
You best option is to use a Regular expressions for this type of validations. If you are ok with using Regular expression then you can try the below approach.
Regular Expression:
^\d{2,4}[-]\d{5,9}$
Explanation:
^ # Beginning of Regular Expression
\d{2,4} # Any numbers with in a range of 2 - 4 in count
[-] # Hyphen in between
\d{5,9} # Any numbers with in a range of 5 - 9 in count
$ # End on Regular Expression
<asp:TextBox ID="txtPhoneNumber" runat="server" TabIndex="2"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtPhoneNumber" ValidationExpression="^\d{1,4}[-]\d{5,9}$" runat="server" ErrorMessage="Please enter a valid number in correct format"></asp:RegularExpressionValidator>
I use regular expression now but had hopped that I could show the textBox like a pattern like this
____-_____
so that the user can see how the pattern look like and doesn't have to enter the - character.
In addition I could use the FilteredTextBoxExtender to prevent all character except number.
I now use FilteredTextBoxExtender but must allow - because this must also be entered.
Member
75 Points
540 Posts
Is it really possible to use the MaskedEditExtender for this kind of phone numer
Jan 17, 2014 03:25 PM|Tojo|LINK
I have this textBox control <asp:TextBox ID="txtInformerPhone" runat="server" />
This input is a telephone number and has the following restrictions.
A valid phone number must have the following requirements. First part of the phone number is either 2 figures or 3 figures or 4 figures. The second part is
either 5 figures or 6 figures or 7 figures or 8 figures or 9 figures.
So the user can enter for example 123-12345
This is valid because the first part containd 3 figures which is valid the second part contains 5 figures which is also valid.
Note the user must also enter this character - that is located between the first part and the second part.
I just wonder is it possible to use MaskedEditExtender for this testBox when I have this requirements
//Tony
All-Star
50831 Points
9895 Posts
Re: Is it really possible to use the MaskedEditExtender for this kind of phone numer
Jan 17, 2014 09:38 PM|A2H|LINK
Hi,
You best option is to use a Regular expressions for this type of validations. If you are ok with using Regular expression then you can try the below approach.
Regular Expression:
Explanation:
You can easily use the regular expression in Asp.Net Regualar Expression Validator
Hope this helps
Edit: Corrected the Regular Expression
Aje
My Blog | Dotnet Funda
Member
75 Points
540 Posts
Re: Is it really possible to use the MaskedEditExtender for this kind of phone numer
Jan 18, 2014 05:09 AM|Tojo|LINK
I use regular expression now but had hopped that I could show the textBox like a pattern like this
____-_____
so that the user can see how the pattern look like and doesn't have to enter the - character.
In addition I could use the FilteredTextBoxExtender to prevent all character except number.
I now use FilteredTextBoxExtender but must allow - because this must also be entered.
//Tony
All-Star
30411 Points
3628 Posts
Re: Is it really possible to use the MaskedEditExtender for this kind of phone numer
Jan 21, 2014 12:11 AM|Fuxiang Zhang - MSFT|LINK
Hi Tojo,
Thank you post the issue to asp.net forum.
According to your description, I think you want to mask the phone number input text using MaskedEditExtender.
For this issue, I think you can mask the input text just using MaskedEditExtender without validation.
Then validate the input value using javascript when it losed focus.
Hope this helps, thanks.
Best Regards!