- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 12:58 PM
I am using this client script to restrict entering negative value and special characters into field,
1) When user enters negative value into field it is populating alert window ,when user clicks ok it setting field value to blank.But I need to set field value to previous value.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var specialCharRegex = /^[0-9].*$/;
if(!specialCharRegex.test(newValue)){
alert('please do not enter negative value and special characters into field');
g_form.setValue('field','');
}
}
Thanks in Advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 01:51 PM
Try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var specialCharRegex = /^[0-9].*$/;
if(!specialCharRegex.test(newValue)){
alert('please do not enter negative value and special characters into field');
g_form.setValue('field',oldValue);
}
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 01:51 PM
Try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var specialCharRegex = /^[0-9].*$/;
if(!specialCharRegex.test(newValue)){
alert('please do not enter negative value and special characters into field');
g_form.setValue('field',oldValue);
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 02:00 PM
Hi Sanjiv,
Thanks for your response.It is not working ,the field value is setting to blank only.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 02:53 PM
FYI. 'oldValue' will always be the value set in the field when the form loads. If the field is empty when the form loads, you would always end up with a blank field with this script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 03:13 PM
In that case, I would also add this script to onSubmit script and not clear the field on onChange. And not allow the user to submit. User can then manually change it and wont loose what he has entered.
Please mark this response as correct or helpful if it assisted you with your question.