Hi there,
I have a modified ASP.NET TextBox control that formats its output as the
phone number, e.g. if you enter "1234567890" it'll change the value to
"123-456-7890". This is done by a javascript function called on "onblur"
event of the textbox.
However, it seems validation happens before the onblur event, therefore if I
enter "1234567890", the validator that checks the phone number is set to
"Invalid" state. How can I format the data in TextBox prior to validation?
Thanks.
<xxx:TelephoneTextBox id="tb" runat="server"></xxx:TelephoneTextBox>
<asp:RegularExpressionValidator id="revCell" runat="server"
ErrorMessage="Cell phone number is invalid" ControlToValidate="tb"
Display="Dynamic" ValidationExpression="((\(\d{3}\)
?)|(\d{3}-))?\d{3}-\d{4}">[Invalid]</asp:RegularExpressionValidator>
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter
writer)
{
base.AddAttributesToRender (writer);
writer.AddAttribute("onblur", "TelephoneTextBox_Format(this)");
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
string scriptFormat =
"<script type=\"text/javascript\">\n" +
" function TelephoneTextBox_Format(source)\n" +
" {\n" +
" var phone = source.value\n" +
" phone = phone.replace(/\\s/g, \"\");\n" +
" if (phone.match(/[^\\d]/))\n" +
" return;\n" +
" if (phone.length != 10)\n" +
" return;\n" +
" source.value = phone.substr(0, 3) + '-' + phone.substr(3, 3) + '-' +
phone.substr(6, 4);\n" +
" }\n" +
"</script>";
Page.RegisterClientScriptBlock("TelephoneTextBox_F ormat", scriptFormat);
} 2 1915
On Fri, 19 Aug 2005 15:31:24 -0400, Oleg Ogurok wrote: Hi there,
I have a modified ASP.NET TextBox control that formats its output as the phone number, e.g. if you enter "1234567890" it'll change the value to "123-456-7890". This is done by a javascript function called on "onblur" event of the textbox.
However, it seems validation happens before the onblur event, therefore if I enter "1234567890", the validator that checks the phone number is set to "Invalid" state. How can I format the data in TextBox prior to validation?
Thanks.
<xxx:TelephoneTextBox id="tb" runat="server"></xxx:TelephoneTextBox>
<asp:RegularExpressionValidator id="revCell" runat="server" ErrorMessage="Cell phone number is invalid" ControlToValidate="tb"
Display="Dynamic" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">[Invalid]</asp:RegularExpressionValidator>
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) { base.AddAttributesToRender (writer); writer.AddAttribute("onblur", "TelephoneTextBox_Format(this)"); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender (e); string scriptFormat = "<script type=\"text/javascript\">\n" + " function TelephoneTextBox_Format(source)\n" + " {\n" + " var phone = source.value\n" + " phone = phone.replace(/\\s/g, \"\");\n" + " if (phone.match(/[^\\d]/))\n" + " return;\n" + " if (phone.length != 10)\n" + " return;\n" + " source.value = phone.substr(0, 3) + '-' + phone.substr(3, 3) + '-' + phone.substr(6, 4);\n" + " }\n" + "</script>"; Page.RegisterClientScriptBlock("TelephoneTextBox_F ormat", scriptFormat); }
Is the server side validator giving the message?
No, once I've set EnableClientScript="False" on the validator and clicked a
button, the server-side validation said OK.
-Oleg.
"intrader" <in******@aol.com> wrote in message
news:pa****************************@aol.com... On Fri, 19 Aug 2005 15:31:24 -0400, Oleg Ogurok wrote:
Hi there,
I have a modified ASP.NET TextBox control that formats its output as the phone number, e.g. if you enter "1234567890" it'll change the value to "123-456-7890". This is done by a javascript function called on "onblur" event of the textbox.
However, it seems validation happens before the onblur event, therefore if I enter "1234567890", the validator that checks the phone number is set to "Invalid" state. How can I format the data in TextBox prior to validation?
Thanks.
<xxx:TelephoneTextBox id="tb" runat="server"></xxx:TelephoneTextBox>
<asp:RegularExpressionValidator id="revCell" runat="server" ErrorMessage="Cell phone number is invalid" ControlToValidate="tb"
Display="Dynamic" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">[Invalid]</asp:RegularExpressionValidator>
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) { base.AddAttributesToRender (writer); writer.AddAttribute("onblur", "TelephoneTextBox_Format(this)"); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender (e); string scriptFormat = "<script type=\"text/javascript\">\n" + " function TelephoneTextBox_Format(source)\n" + " {\n" + " var phone = source.value\n" + " phone = phone.replace(/\\s/g, \"\");\n" + " if (phone.match(/[^\\d]/))\n" + " return;\n" + " if (phone.length != 10)\n" + " return;\n" + " source.value = phone.substr(0, 3) + '-' + phone.substr(3, 3) + '-' + phone.substr(6, 4);\n" + " }\n" + "</script>"; Page.RegisterClientScriptBlock("TelephoneTextBox_F ormat", scriptFormat); } Is the server side validator giving the message?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David Smith |
last post by:
What I want to be able to do:
A textbox is available that the user can enter information into.
Specifically (for the purposes of this post), the user is asked to
enter a number, and that number...
|
by: Hazzard |
last post by:
I just realized that the code I inherited is using all asp.net server
controls (ie. webform controls) and when I try to update textboxes on the
client side, I lose the new value of the textbox when...
|
by: Pham Nguyen |
last post by:
Has anyone seen an example of a textbox server control that has
built-in client-side validation? I'd like to build a server control
that extends the System.Web.UI.WebControls.TextBox class to allow...
|
by: Bryan |
last post by:
I trying to figure out out to validate a textbox inside a repeater once a
person presses a button on a repeater.
Here's the validation Code behind:
Please be aware that line e.Item.ItemIndex...
|
by: The Eeediot |
last post by:
Hello, Folks...
I'm almost becoming a regular to this newsgroup.
I am trying to display the contents of an MS-SQL Text field to a TextBox in ASPdotNET. The text in this field contains all...
|
by: Mike |
last post by:
So here's the situation (.NET 2.0 btw):
I have a form, and on this form is a textbox among many other
databound controls. The textbox is bound to a field in a data table
via the Text property. ...
|
by: =?Utf-8?B?SmVycnkgSg==?= |
last post by:
Hello,
I am using asp.net 2003 using C#. I am creating textboxes dynamically and
want to validate to make sure the user can only input an integer. I don't
think I can use the validators...
|
by: mageswar005 |
last post by:
Hi Guys,
My array textbox validation is not working fine,my code is given below please help me immediately.
function validation()
{
var chks =...
|
by: mrutyunjaya |
last post by:
hello, i have two textbox column and one button control in gridvie when i click button it will ask plese enter price in first textbox . when enter values it is asking again. how to pass...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |