OSDN Git Service

ae6723236d224f241703328b366f6320878e209e
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / javascript / numbercheck.js
1 /**
2   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
3   * Copyright (C) 2002-2010 The Nucleus Group
4   *
5   * This program is free software; you can redistribute it and/or
6   * modify it under the terms of the GNU General Public License
7   * as published by the Free Software Foundation; either version 2
8   * of the License, or (at your option) any later version.
9   * (see nucleus/documentation/index.html#license for more info)
10   *
11   * script the check (on the clientside) if a entered value
12   * is a valid number and remove the invalid chars
13   *
14   * $Id$
15   * $NucleusJP: numbercheck.js,v 1.3 2006/07/12 07:11:47 kimitake Exp $
16   */
17
18 function checkNumeric(f)
19 {
20         newval='';
21         dot = false;
22         for (i = 0; i < f.value.length; i++) {
23                 c = f.value.substring(i,i+1);
24                 if (isInteger(c) || ((c == '.')&&(dot == false)) || ((i == 0)&&(c == '-'))) {
25                         newval += c;
26                         if (c == '.') {
27                                 dot = true;
28                         }
29                 }
30         }
31         f.value = newval;
32 }
33
34 function isInteger(value)
35 {
36         return (parseInt(value) == value);
37 }