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

Home Posts Topics Members FAQ

validation for textbox

18 New Member
Hi,

how to validate the textbox accepts 10 Numbers only.
give sample code....
Apr 8 '08 #1
5 2134
mrhoo
428 Contributor
Which ten numbers do you allow?

10 digits?
Expand|Select|Wrap|Line Numbers
  1. inputelement.onchange=function(e){
  2.     e= window.event || e;
  3.     e= e.target || e.src;
  4.     var M= /^(\d{10})$/.exec(e.value);
  5.     return e.value= M? M[1]: '';
  6. }
Apr 8 '08 #2
malav123
217 New Member
Hi,
just set the maxlength of textbox = 10 and to check that user has entered the 10 digits write following code in javascript...
Expand|Select|Wrap|Line Numbers
  1. function check()
  2. {
  3.          if(textbox1.value.length!=10)
  4.         {
  5.             alert("Please Enter 10 digits for textbox1");
  6.             textbox1.focus();
  7.             return false;
  8.         }
  9. }
  10.  
Apr 8 '08 #3
gits
5,390 Recognized Expert Moderator Expert
Hi,
just set the maxlength of textbox = 10 and to check that user has entered the 10 digits write following code in javascript...
Expand|Select|Wrap|Line Numbers
  1. function check()
  2. {
  3.          if(textbox1.value.length!=10)
  4.         {
  5.             alert("Please Enter 10 digits for textbox1");
  6.             textbox1.focus();
  7.             return false;
  8.         }
  9. }
  10.  
that code just checks for 10 characters without checking the type of it ... so it would be possible to enter 10 alpha-chars or numbers or a mixture ... so mrhoo's (see post #2) solution is to prefer for the original requirement ...

kind regards
Apr 8 '08 #4
malav123
217 New Member
that code just checks for 10 characters without checking the type of it ... so it would be possible to enter 10 alpha-chars or numbers or a mixture ... so mrhoo's (see post #2) solution is to prefer for the original requirement ...

kind regards
Yes you are right i have only specified for length 10, for numeric value checking "isNaN" is very useful function of javascript... right ?
Apr 9 '08 #5
gits
5,390 Recognized Expert Moderator Expert
yup ... you are right ... using isNaN() or a regExp like mrhoo did are the common ways to check such things ...

kind regards
Apr 9 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2791
by: Rick | last post by:
I have an interesting problem when I run the following code in Netscape (7.02) vs. IE. This page works great in IE and all my controls bring up the validation summary dialog box if the required field is not filled out. However in Netscape NONE of the required field validations occurs at all in Netscape. The form is posting correctly because I can walk through the post back process. Any ideas why this is happening or how to fix it?
7
2876
by: A.M | last post by:
Hi, I have a validation control in my page that upon any invalid data, it disables all buttons in the page. basicly i don't have any postback in the page if the validator finds any error. How can have the validator just disable certain control's postback and other part of page continue their functionality. Thanks,
0
2164
by: Boltar | last post by:
Hello, I am trying to use a CustomValidator control to perform client-side validation via a server callback. I have an example below that validates if a textbox contains an odd number. I realize that I can use client-side javascript entirely for this, I have just created a simplified example. My actual callback validation
1
1682
by: Arpan | last post by:
I have a Web Form in my ASPX page which makes use of Web controls & incorporates validation controls. This is the code snippet that does the needful: <form runat=server> NAME:<asp:TextBox id="txtName" runat=server/> <asp:RequiredFieldValidator ControlToValidate="txtName" ErrorMessage="Enter your name!" Display="Dynamic" runat=server/> <%-- some other server controls here --%> <asp:Button id="but1" Text="SUBMIT" OnClick="show"...
2
6716
by: Tim Frawley | last post by:
Source code attached indicates my problem with validation and a button bar save button. Fill the Textbox with some text then tab off the control. The message box will display the text in the textbox from the Validating event. Now put the focus back on the textbox click the button bar button. Nothing happens. The form causes validation is true, so is the button bar and the control.
1
1820
by: Buddy Ackerman | last post by:
I don't know what the problem is. I have a form with several controls that need to be validated, I put a validation group in every form control, every validatoino control, the submit button and the validation summary control. I want it to do client side validation so I set every validation control display property to none and set the validation summary control to ShowMessage to true and ShowSummary to false. Als form controls set...
2
9107
by: winnie_us99 | last post by:
Hi All, I am trying to do validation on my text field before going to the next page to create a user. It doesn't look like the next button will fire any validation. Am I missing something? Can anyone please help me with this? I am attaching my code piece. Thank you in advance for your help. Wing
12
2056
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the validation controls to do this? Thanks.
6
3364
by: Jon Paal | last post by:
validation doesn't fire what's missing ????? /////// ---- code -----/////////////////////////// Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click If page.isValid then ..... end if
4
8243
by: HenrikL | last post by:
Hi. I have a textbox that have a binding on it with converter and validationrules. When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers that are connect to it and it works as it should.. What I wanna to do it in some special case I wan to test tb.Text.Equals("myTestStr") or if the text lenght too large etc.. and I wanna same behave as a validation has error on the textbox if the...
0
9710
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
9589
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
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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
9163
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...
0
6858
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...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.