Validating Social Security Numbers through Regular Expressions - c#

I want to do like this -
I want to do when I put cursor in the text box it should be empty and how I can show 000-00-0000 format while page load.
I have tried this-
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="TextBox7" ErrorMessage="Social Security No. is wrong."
ValidationExpression="^\d{3}-\d{2}-\d{4}$">
</asp:RegularExpressionValidator>
but its not showing 000-00-0000 when I load the page and when I put cursor in the text box it should disappear the 000-00-0000.
Thanks in advance.

Are you looking for a placeholder? Given an HTML input as
<input type="text" placeholder="000-00-0000" />
you will see an input box with ghosted letters 000-00-0000 which disappear and reappear when the user focuses or blurs the element. To do this in Asp.net, you might try
<asp:textbox placeholder="000-00-0000" runat="server" />
Additionally, if a user does not enter the - characters, could the ValidationExpression be modified to be optional?
ValidationExpression="^\d{3}-?\d{2}-?\d{4}$"
Then either 000000000 and 000-00-0000 would be accepted, which you could deal with server-side when the form is submitted.

Related

TextMode.Phone doesn't do any validation?

On my aspx page I have a textbox, which is placed on a modal window, together with an OK button:
<asp:TextBox runat="server" ID="contactInfo" TextMode="Phone" ToolTip="Please enter your phone number">01234/567890</asp:TextBox>
<asp:Button ID="btnOK" runat="server" Text="Ok" OnClick="btnOk_Click" />
However, the TextMode="Phone" doesn't seem to do any validation at all. Even if I enter absolute nonesense like "Hi, this is a text and definitely not a phone number" the page will not complain. If, for example, I change the TextMode to TextMode="Email", then a message will appear asking me to enter a valid e-mail address and the modal window stays open, no matter how often I try to click the OK button.
Right now I have to validate the phone number on the client side (as changing the TextMode to Number introduces a whole lot of other problems), but I would like to use the "framework solution" just as I am able to with TextMode.Email.
Is the validation check really not implemented for TextMode.Phone? I couldn't find anything helpful regarding this topic.
<asp:TextBox TextMode="Phone"> is a .NET element that gets rendered into <input type="tel"> HTML element and this HTML element does not automatically validate.
From MDN:
<input> elements of type "tel" are used to let the user enter a
telephone number. Unlike <input type="email"> and <input type="url"> ,
the input value is not automatically validated to a particular format
before the form can be submitted — this is because formats for
telephone numbers vary so much around the world.
You can validate using a <asp:RegularExpressionValidator> with your desired regex.
For example:
<asp:RegularExpressionValidator ID="revPhone" runat="server"
ErrorMessage="Not a valid phone" ControlToValidate="contactInfo"
ValidationExpression="^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$">
</asp:RegularExpressionValidator>

Can you Format input from a text box in C# without a masked text box?

I need to format many text boxes in my C# web application some to accept 13 numbers some to accept 10 numbers and some to accept a combination like "IS112" I haven't been able to find anything that wasnt a masked text box using AJAX Extensions and am just checking to see if there is any way before I have to add the extension and remake and ID my text boxes.
<asp:TextBox ID="txtBox" runat="server" MaxLength="13"></asp:TextBox>
This is a text Box
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"runat="server" ControlToValidate="txtBox"
ValidationExpression="^(\d{0,13})$" ErrorMessage="*Invalid Text Length:" text="*" Display="Dynamic" />

RadSpell display redlines

I have a multiline checkbox. I want to use RadSpell.
But everytime I insert text on the textbox it doesn't display red lines.
How can i do this?
here is my code.
<telerik:RadTextBox ID="textbox1" runat="server" TextMode="MultiLine" Rows="4"
Columns="51" Width="401px" Font-Size="10" Font-Names="Calibri" />
<telerik:radspell id="RadSpell1" runat="server" DictionaryLanguage="English"
controltocheck="textbox1" spellcheckprovider="PhoneticProvider"
supportedlanguages="en-US,English" ButtonType="None"/>
NOTE: No buttons needed.
I just want to show all the words that are misspelled.
That's a browser feature - inline spellchecking. All modern browsers have it. Well, IE doesn't, but why should we call it modern? ;-)
What RadSpell can do for you is a popup with suggestions and information.
EDIT: Forgot to mention you can trigger RadSpell's check programmatically: http://www.telerik.com/help/aspnet-ajax/spell-client-side-api.html. Look for the startSpellCheck() method. For example in the onblur event.

Restricting user entering html tag in textbox using validation control in asp.net c#

I have page user creation and it contains textbox control. I want to restrict user entering html tag in i.e < and > sign in textbox using .net validation control.
Can any one help me about in this?
I also want to restrict double quote i.e " and caret sign ^ can you please tell me how to write expression for that???
Use a regularexpressionvalidator...
<asp:textbox id="theTextbox" runat="server" />
<asp:regularexpressionvalidator id="regexValiator" runat="server"
controltovalidate="theTextbox"
errormessage='<, >, ", and ^ not allowed'
display="Dynamic"
validationexpression='([^<>\"\^])*' />
Actually, by default ASP.Net dissallow HTML content to be entered in form fields. No need for further validation.
you can try the following code in your aspx code:
<asp:textbox id="txtBox" runat="server" />
<asp:RegularExpressionValidator controltovalidate="txtBox" ValidationExpression="([a-z]|[A-Z]|[0-9]|[ ]|[-]|[_])" ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"></asp:RegularExpressionValidator>
and now you can modify the regular expression to fit your case.

.NET two "forms" on a page and their validators

I have got a page that has 2 "forms" (What I mean by a form here is a Panel consisting of: textboxes, validators and a button).
(I got 2 here because one of them is actually on the MasterPage, shown all the time)
The problem is when you try to submit to one of the form, it will validate the other form, which of course is blank and invalid.
How do you solve this problem?
Thank you.
Your problem can be solved with asp.net ValidationGroups.
http://weblogs.asp.net/scottgu/archive/2004/10/24/246945.aspx
Basically, you group the controls to be validated using a uniquely named validation group. Like so:
<asp:Textbox ID="txt" runat="server" />
<asp:RequiredFieldValidator id="rfv" runat="server" ControlToValidate="txt" ValidationGroup="masterGroup">* Required!</asp:RequiredFieldValidator>
<br />
<asp:Button id="btnSubmitMaster" runat="server" Text="Submit!" ValidationGroup="masterGroup" />
If you group your inputs like this, then assign the validation group to the control that submits the form, the inputs in the other validation groups won't be validated.

Categories