JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 2nd, 2008, 03:03 PM
nikko50 nikko50 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 273 nikko50 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 4 m 18 sec
Reputation Power: 5
Validate numbers

Hi all. I would like to validate a number a user enters into my form. This number can be 5 or 6 numerical numbers or have 6 numeric numbers seperated by a dash with 6 more numeric numbers like so 123456-123456. How can I do this. I'm stumped on this one. Please help me.
Tracy

Reply With Quote
  #2  
Old May 2nd, 2008, 03:06 PM
GameYin GameYin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Whiteford, MD
Posts: 348 GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 11 h 54 m
Warnings Level: 5
Reputation Power: 60
Send a message via AIM to GameYin
MySpace
Are the numbers randomly generated?
__________________
Adwords Professional
You can give me

Reply With Quote
  #3  
Old May 2nd, 2008, 03:14 PM
Joseph Taylor's Avatar
Joseph Taylor Joseph Taylor is offline
Text Ninja
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2005
Location: Vancouver, British Columbia, Canada
Posts: 596 Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 1 h 12 m 43 sec
Reputation Power: 107
Send a message via Skype to Joseph Taylor Send a message via XFire to Joseph Taylor
Quote:
How can I do this. I'm stumped on this one. Please help me.


Regular expressions.

/^(?:\d{5,6}|\d{6}-\d{6})$/ will match the pattern you described. Refer to Mozilla's Developer Section to see how to match a regular expression against a string.
Comments on this post
vbrtrmn agrees!

Reply With Quote
  #4  
Old May 2nd, 2008, 05:59 PM
nikko50 nikko50 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 273 nikko50 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 4 m 18 sec
Reputation Power: 5
Here is what I have so far but I can't get it to work. Please help.
Tracy
Code:
<script>

function validateCharge(theForm){

//VALIDATE CHARGE
if(theForm.charge){
 if(!theForm.charge.value.match(/^\d{5}$/) || !theForm.charge.value.match(/^\d{6}$/)){
 alert("Please input a valid Charge Account!")
theForm.charge.style.backgroundColor='pink';
theForm.charge.focus();
return false
}}


  return (true);

}


</script>

<form method="POST" name="theForm" onsubmit="return validateCharge(theForm)" action="--WEBBOT-SELF--">
 
  <input type="text" name="charge" size="20"></p>
  <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

Reply With Quote
  #5  
Old May 2nd, 2008, 07:32 PM
Joseph Taylor's Avatar
Joseph Taylor Joseph Taylor is offline
Text Ninja
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2005
Location: Vancouver, British Columbia, Canada
Posts: 596 Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 1 h 12 m 43 sec
Reputation Power: 107
Send a message via Skype to Joseph Taylor Send a message via XFire to Joseph Taylor
The biggest problem with your code is here:

Code:
<form method="POST" name="theForm" onsubmit="return validateCharge(theForm)" action="--WEBBOT-SELF--">


Change onsubmit="return validateCharge(theForm)" to onsubmit="return validateCharge(this)" and it might start rejecting input of anything other than five or six consecutive digits.

Reply With Quote
  #6  
Old May 3rd, 2008, 02:06 AM
KorRedDevil's Avatar
KorRedDevil KorRedDevil is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Aug 2005
Location: Bucharest ROMANIA
Posts: 1,506 KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 14 h 12 sec
Reputation Power: 55
Send a message via Yahoo to KorRedDevil
Code:
  return (true);

is useless and redundant. If no certain value returned, the function returns undefined, which will allow the submit same as a true returned, because the only value which prevents the submit action is false ex: onsubmit="return false"
__________________
HELP SAVE ANA

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Validate numbers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway