开发者

Javascript + Format of Integer Using Replace Function & Split Function

开发者 https://www.devze.com 2023-02-17 15:08 出处:网络
In JavaScript function, I want to concatenate a numbers. Text Box value format `1.234.567,89` But I split the value using \",\" and access two array having value as

In JavaScript function, I want to concatenate a numbers.

Text Box value format `1.234.567,89` 

But I split the value using "," and access two array having value as

First Array = 1.234.567

Then I used replace function to replace (.) dot by nothing, to access simple integer : 1234567

Code Sample

var number = element.value;
var numberArray = number.split(',');
开发者_StackOverflow社区numberArray[0] = numberArray[0].replace(/./g,"");
alert('numberArray[0]:'+numberArray[0]+'::numberArray[1]:'+numberArray[1]);

But I am getting numberArray[0] as null. Suggest something !!!


Do this instead

numberArray[0] = numberArray[0].replace(/[.]/g,"");

. (dot) matches every character in regex, enclosing it in [] changes the meaning

0

精彩评论

暂无评论...
验证码 换一张
取 消