Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2004, 02:31 AM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default JAVASCRIPT input validation ! Please help !

Hi !
Who could help me with a javascript ?

What I need:

We have pages, where a user could input amounts.
These amounts could only be numbers (e.g. 100) with OR without an "M" (for million) or an "T" (for thousand):

e.g. 100 (hundred) , 100M (one hundred million), 100T (one hundred thousand) and so on.

- I need a validation script (which can be used for onKeyPress and onBlur) which ONLY accepts ".1234567890MT".

- This script has also to check whether the user puts in a "," . If so, the script has to replace this with an "."

- Only ONE "." is allowed, this means, if the user tries to put in: "100.000.000", the script should take out the last ".", because ONLY ONE "." is allowed.

-It should always capitalize the "m" or "t", whgen a user put that in. e.g. : 100m -> 100M

At least, there should be a parameter which thell the function, in the user is allowed to put in a NEGATIVE value or NOT.

e.g.: function_xy(notNegative)...

if notNegatibe == true -> no negative values are allowed, the script should also not allow to put in a "-" before the number, M or T is allowed

if notNegative == false -> the user could input 0-9, negative values are allowed, the user can put in a "-" before the number, M or T is allowed

The first function should be e.g. validOnKeyPress(notNegative);

The second function should be e.g. validFieldOnBlur(notNegative);

I hope, this is not to much :)

Could somebody help me here ?

This would be GREAT !!!

regards
Michael


 
Old July 15th, 2004, 09:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

u should use RegularExpression to format ur Input Control & validate it. Check the MSDN for RegularExpression.

HTH

Always:),
Hovik Melkomian.
 
Old July 19th, 2004, 10:47 AM
Authorized User
 
Join Date: May 2004
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

I used regualr expressions for something similar recently. Once you understand the basic rules its fairly simple but very powerfull.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Input Validation sams ASP.NET 2.0 Professional 4 June 12th, 2007 03:29 AM
Validation to input fields amol_0008 XML 1 May 30th, 2007 04:36 AM
Input validation shs BOOK: Beginning ASP.NET 1.0 14 January 6th, 2005 01:03 PM
Input Validation Maxood C++ Programming 11 August 6th, 2004 02:55 PM
Validation of TextBox Input bpgadhia ASP.NET 1.0 and 1.1 Professional 1 March 16th, 2004 05:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.