Regex to accept numbers and can only accept one dot for decimals.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:11 AM - edited 06-11-2024 11:38 AM
I am trying to write a regex with on change client and tried the below. It needs to accept numbers as below
ex: (should accept numbers and dots)
12345
12345.67
12345.678xxx (No limitation on decimals unless its not possible)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Accept numbers with only dots
var pattern = /^(([0-9.]?)*)+$/;
if (!pattern.test(newValue)) {
g_form.clearValue('u_amount');
g_form.showFieldMsg('u_amount', 'Accepted format : 354621.32', 'error', true);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:21 AM
@pardhiv If you wish to have just one dot in the number and have numbers upto two decimal places then you can try the following regular expression.
/^(([0-9]+\.?[0-9]{2}?)*)+$/gm
It accepts following combinations.
1234
1234.12
Invalid combination
1234.123
1234.12.1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:56 AM
try this
^\d+(\.\d{1,2})?$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:58 AM
try this
^\d+(\.\d{1,2})?$