473,396 Members | 1,929 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,396 software developers and data experts.

number validation and string validation

1
how to validate phone number,age using javascript with html.reply with simple source code .i am well in javascript. give explanation with simple example
Sep 1 '07 #1
3 2752
phvfl
173 Expert 100+
Hi Haji,

Welcome to TSDN...

How accurate are you wanting the validation to be and what are the conditions?

I would assume that the age one is quite simple for example it must be a number, greater than or equal to 0 (incase you have some very young users :)) and less than 120 (unless you have very old users).

The phone number is more involved as it depends on the country that the telephone number is in due to differences in format. If the condition is as simple as it needs to be a number and in a certain length range then this is simple to code, more complex matching can be done using regular expressions to make sure that the submitted phone number matches a pattern.

Sample code for the age (based on the conditions above would be):
Expand|Select|Wrap|Line Numbers
  1. function checkAge($age){
  2.   // Create a variable to return, set initial value to false,
  3.   // this will be changed if the checks are passed.
  4.  
  5.   var $blAge = false;
  6.  
  7.   //Check if the $age is a number and not an empty string.
  8.   if (!isNaN($age) && $age.length>0){
  9.  
  10.     // Make sure $age within the defined range.
  11.     if($age>=0 && $age<120){
  12.       // $age is a valid age so change the return value to true.
  13.       $blAge=true
  14.     }
  15.   }
  16.  
  17.   //return the return value
  18.   return $blAge;
  19. }
  20.  
The code above creates a function that checks the value passed in and returns true if it is a valid age or false otherwise. The two if conditions could be combined into one, I have put them seperately for clarity.

Please let me know your criteria for the phone number and I can go through that with you.
Sep 1 '07 #2
pbmods
5,821 Expert 4TB
Heya, Haji. Welcome to TSDN!

TSDN members are expected to write their own code. We're happy to help you out if you have specific questions, but you can't realistically expect someone to do your coding for you on a free forum.
Sep 2 '07 #3
acoder
16,027 Expert Mod 8TB
how to validate phone number,age using javascript with html.reply with simple source code .i am well in javascript. give explanation with simple example
For the phone number, use regular expressions.
Sep 2 '07 #4

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

Similar topics

2
by: Laphan | last post by:
Hi All I'm after a Tax/VAT number validation script that I can tag onto the onClick event of my submit button before submission. I've seen a lot of these as server side, but I'm trying to keep...
2
by: Andy Eshtry | last post by:
I need to validate a textbox control using the validation control so that user can enter only string (character) type not numbers I used comparevalidator and set the "Operator" property to...
6
by: JIM.H. | last post by:
How can I grantee that user enter only number in the textbox. If possible accept ","and "." in the number. Can I do this?
1
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i...
2
by: Marcin Cenkier | last post by:
Hi, I want to validate a DOM document, and if I build DOM from a stream using documentBuilder.parse() validation using validator.validate(DOMSource) works, but if I create the same document...
9
by: campbellwarren | last post by:
Does anyone know how I could limit the number of rows allowed in a MS Access table... want to limit it to 1.
6
by: lists | last post by:
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation...
1
by: matthewzammit | last post by:
I have an XML element <val> with child elements. I'd like to be able to include any of the child elements, or leave them out, without having to write default null values each time for unneeded...
3
by: ryushinyama | last post by:
I am wanting to remove 1's that Canadian customers put in front of their numbers because when FedEx imports them for shipping they leave the 1 and cut off the last number. Other countries numbers...
8
by: Bryan | last post by:
I want my business objects to be able to do this: class Person(base): def __init__(self): self.name = None @base.validator def validate_name(self): if not self.name: return
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.