473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

validation for textbox

Hi,

how to validate the textbox accepts 10 Numbers only.
give sample code....
Apr 8 '08 #1
5 2114
mrhoo
428 256MB
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 100+
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 Expert Mod 4TB
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 100+
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 Expert Mod 4TB
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
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...
7
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...
0
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...
1
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...
2
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...
1
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...
2
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...
12
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...
6
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...
4
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.