Allow only numbers or decimal point input Javascript

/ **
* Text box only allows decimal point when entering numbers or call this method.
* Obj: the text box object
* /
function clearNoNum (obj) (
if (inNaN (obj.value)) (
obj.value = obj.value.replace (/ [^ \ d.] / g ,""); / / first replace all non-numbers, except numbers and.
obj.value = obj.value.replace (/ ^ \. / g ,"");// must ensure that digital rather than the first.
obj.value = obj.value.replace (/ \. (2,) / g ,"."); / / ensure that only the emergence of a. but no more.
/ / Guarantee. Only occurs once, and not more than twice
obj.value = obj.value.replace (".","$#$"). replace (/ \. / g ,""). replace ("$#$",".");
)
)

分类:Web 时间:2010-09-20 人气:150
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.097 (s). 12 q(s)