Showing posts with label needing. Show all posts
Showing posts with label needing. Show all posts

Wednesday, March 21, 2012

Need help with regex for Phone Validation for MaskedEditExtender Control

I'm needing some help in getting maybe a regex to work with the format I've put into my MaskedEditExtender control. So far I have this but need a little help in figuring out how to get the correct validatoni in here. I assume I must set the MaskType to none when establishing a custom validation expression in the MaskedEditValidator control.

 
<tr> <td align="right" width="220px"><asp:Label ID="lblPrimaryContactPhone" runat="server" /> <td align="left" valign="middle"> <asp:TextBox ID="TextBox1" runat="server" Width="180px" ValidationGroup="MKE" /> <cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1" Mask="(999) 999-9999" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" MaskType="None" ErrorTooltipEnabled="True" /> </td> <td align="left"><asp:TextBox ID="txtPrimaryContactPhone_Area" runat="server" /></td align="left"><td>-</td><td align="left"><asp:TextBox ID="txtPrimaryContactPhone_Prefix" runat="server" /><td>-</td><td align="left"><asp:TextBox ID="txtPrimaryContactPhone_Suffix" runat="server" /></td> </tr><tr> <td align="right"> <cc1:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="MaskedEditExtender6" ControlToValidate="TextBox1" IsValidEmpty="False" EmptyValueMessage="phone is required" InvalidValueMessage="phone format is invalid" Display="Dynamic" TooltipMessage="" InvalidValueBlurredMessage="" ValidationGroup="MKE" ValidationExpression="/^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/" /> </td></tr>

HI There,

Im assume the format that you after is like follow:

1) first character range from 2- 9 folow by 2 digit

2) follow by 3 and 4 digit

If this is what are you trying to do

You regularexpression seem to be alright, all you need to remove is "\" sign

ValidationExpression="^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$" />

^ = startwith

$ = endwith

Hope this is help