How to restrict a field to not allow commas and £ symbol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2020 06:28 AM
Hi All.
I currently have a onChange Client Script which allows the number value be two decimal places. But I would like to redistrict this more to not include comma and also the £ symbol.
2 error examples
20,000.00
£20000.00
Correct example
20000.00
Here is the code I have at the moment
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regex = /[0-9]*\.[0-9]{2}/g;
var answer = regex.test(newValue);
if (answer == false){
alert('Please enter a valid number. The number must be a float with two decimal places.');
g_form.setValue('value', '');
}
}
any ideas were and what I could add to achieve this
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2020 06:42 AM
Hi,
You should just use the field of type integer, it will remove any $ or £ sign itself, allows decimal too.
i think restricting £ alone is not going to solve the issue as people might add other currencies.
But it does add , but you will be able to remove it via script easily if it is also not acceptable.
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2020 07:08 AM
here is the regex which will restrict commas (,) and Pound (£) - var regex = /^[^,|£]+$/g;
Try below in the background script for quick look.
var newValue = '£abc12345';
var regex = /^[^,|£]+$/g;
var answer = regex.test(newValue);
gs.info(answer);
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad