473,804 Members | 3,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reformat TextBox value prior validation

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:TelephoneT extBox id="tb" runat="server"> </xxx:TelephoneTe xtBox>

<asp:RegularExp ressionValidato r id="revCell" runat="server"
ErrorMessage="C ell phone number is invalid" ControlToValida te="tb"

Display="Dynami c" ValidationExpre ssion="((\(\d{3 }\)
?)|(\d{3}-))?\d{3}-\d{4}">[Invalid]</asp:RegularExpr essionValidator >
protected override void AddAttributesTo Render(System.W eb.UI.HtmlTextW riter
writer)
{
base.AddAttribu tesToRender (writer);
writer.AddAttri bute("onblur", "TelephoneTextB ox_Format(this) ");
}
protected override void OnPreRender(Eve ntArgs e)
{
base.OnPreRende r (e);
string scriptFormat =
"<script type=\"text/javascript\">\n " +
" function TelephoneTextBo x_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.RegisterCl ientScriptBlock ("TelephoneText Box_Format", scriptFormat);
}

Nov 19 '05 #1
2 1933
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:TelephoneT extBox id="tb" runat="server"> </xxx:TelephoneTe xtBox>

<asp:RegularExp ressionValidato r id="revCell" runat="server"
ErrorMessage="C ell phone number is invalid" ControlToValida te="tb"

Display="Dynami c" ValidationExpre ssion="((\(\d{3 }\)
?)|(\d{3}-))?\d{3}-\d{4}">[Invalid]</asp:RegularExpr essionValidator >
protected override void AddAttributesTo Render(System.W eb.UI.HtmlTextW riter
writer)
{
base.AddAttribu tesToRender (writer);
writer.AddAttri bute("onblur", "TelephoneTextB ox_Format(this) ");
}
protected override void OnPreRender(Eve ntArgs e)
{
base.OnPreRende r (e);
string scriptFormat =
"<script type=\"text/javascript\">\n " +
" function TelephoneTextBo x_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.RegisterCl ientScriptBlock ("TelephoneText Box_Format", scriptFormat);
}

Is the server side validator giving the message?
Nov 19 '05 #2


No, once I've set EnableClientScr ipt="False" on the validator and clicked a
button, the server-side validation said OK.

-Oleg.

"intrader" <in******@aol.c om> 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:TelephoneT extBox id="tb" runat="server"> </xxx:TelephoneTe xtBox>

<asp:RegularExp ressionValidato r id="revCell" runat="server"
ErrorMessage="C ell phone number is invalid" ControlToValida te="tb"

Display="Dynami c" ValidationExpre ssion="((\(\d{3 }\)
?)|(\d{3}-))?\d{3}-\d{4}">[Invalid]</asp:RegularExpr essionValidator >
protected override void
AddAttributesTo Render(System.W eb.UI.HtmlTextW riter
writer)
{
base.AddAttribu tesToRender (writer);
writer.AddAttri bute("onblur", "TelephoneTextB ox_Format(this) ");
}
protected override void OnPreRender(Eve ntArgs e)
{
base.OnPreRende r (e);
string scriptFormat =
"<script type=\"text/javascript\">\n " +
" function TelephoneTextBo x_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.RegisterCl ientScriptBlock ("TelephoneText Box_Format",
scriptFormat);
}

Is the server side validator giving the message?


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4290
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 has an upper limit. I want to do validation on what the user enters as they type it in. I set up an event handler for KeyPress that restricts them from being able to enter non-numeric characters (only allowing numbers, decimal point, control...
2
8407
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 submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
2
3923
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 javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I did some work on was having the control implement the IValidator interface and basically recreating...
1
5338
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 is invalid. Because I don't know how to pass the repeater as the object through the OnServerValidate Tag in the ASP.NET side. What I really need is to pull the ItemIndex from the actual repeater.
6
2248
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 sorts of characters including cheverons (i.e. ">" and "<") and occasionally I get the following error condition (listed below). Is there anything I can do to avoid it? I use the simple line txtArticle.Text = datareader("Article") in my code to populate...
0
2516
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. In this table there are multiple columns that cannot be NULL, which, are bound to other controls (but they're not really important at this time). I create a new row via the currency manager like so: _currencyManager.AddNew() _currentRow =...
2
4909
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 because I don't know what the ID of the textbox is ahead of time. I am trying to do it with javascript with a tableCell.Attributes.Add. I'm not sure I can do what I am trying.
9
35690
mageswar005
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 = document.getElementsByName('rr');//here rr is the name of the textbox for (var i = 0; i < chks.length; i++) {
2
12951
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 textboxid in javascript .my code is function validation() { alert("hi")
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.