- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 03:20 AM
Hi All ,
I have created single line text that one hour field , in that only number is allowed that one (Indicate the number of hours (maximum 39 hours and one decimal place allowed like 39.1) ) and character is not allowed , can you tell how to get this requirement.
Thanks,
Chandan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 03:33 AM - edited 12-08-2023 03:35 AM
Hello @chandan31
use this onchange client script,
select your field here -
I have trial and tested this script and is working as expected.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = g_form.getValue('your_field_name'); //use your field name
// Regular expression to match the desired format (maximum 39 hours and one decimal place)
var regex = /^([1-9]|[1-3][0-9])(\.\d)?$/;
// Check if the value matches the regex pattern
if (!regex.test(fieldName)) {
// If the value doesn't match, show an error message
alert('Please enter a valid number with one decimal place, maximum 39 hours.');
// Set the field value to an empty string or another default value
g_form.setValue('your_field_name', '');
}
//Type appropriate comment here, and begin script below
}
Outputs:-
1) Doesnt accept alphabets-
2) will not accept more than 39
3)More then one decimal will not be accpeted
Please check and Mark Correct and Helpful if it really helps you.
Regards,
Prashant Ahire
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 03:33 AM - edited 12-08-2023 03:35 AM
Hello @chandan31
use this onchange client script,
select your field here -
I have trial and tested this script and is working as expected.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = g_form.getValue('your_field_name'); //use your field name
// Regular expression to match the desired format (maximum 39 hours and one decimal place)
var regex = /^([1-9]|[1-3][0-9])(\.\d)?$/;
// Check if the value matches the regex pattern
if (!regex.test(fieldName)) {
// If the value doesn't match, show an error message
alert('Please enter a valid number with one decimal place, maximum 39 hours.');
// Set the field value to an empty string or another default value
g_form.setValue('your_field_name', '');
}
//Type appropriate comment here, and begin script below
}
Outputs:-
1) Doesnt accept alphabets-
2) will not accept more than 39
3)More then one decimal will not be accpeted
Please check and Mark Correct and Helpful if it really helps you.
Regards,
Prashant Ahire
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 03:51 AM
Did this helped you?
Please appreciate the efforts of community contributors by marking appropriate response as correct answer.
Thanks