OSDN Git Service

Subversion由来のタグを削除
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / javascript / numbercheck.js
1 /**
2   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
3   * Copyright (C) 2002-2012 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
15 function checkNumeric(f)
16 {
17         newval='';
18         dot = false;
19         for (i = 0; i < f.value.length; i++) {
20                 c = f.value.substring(i,i+1);
21                 if (isInteger(c) || ((c == '.')&&(dot == false)) || ((i == 0)&&(c == '-'))) {
22                         newval += c;
23                         if (c == '.') {
24                                 dot = true;
25                         }
26                 }
27         }
28         f.value = newval;
29 }
30
31 function isInteger(value)
32 {
33         return (parseInt(value) == value);
34 }