Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to set numeric value for a variable in service catalog like mobile number...

bvk
Kilo Contributor

how to set numeric value for a variable in service catalog like mobile number...

1 ACCEPTED SOLUTION

You can use this an onchange client script to only accept numeric. If user is trying to write non numeric value then error occurs: Please enter numeric values only in the phone number field



function onChange(control, oldValue, newValue, isLoading) {  


    if (!isLoading) {  


          if(newValue != '') {  


                //check to see if there are any non numeric characters in the string  


                if(isNaN(newValue) == true) {  


                      alert("Please enter numeric values only in the phone number field");  


                      g_form.setValue('phone_number', '');  


    }  


  }  


}  


}  



And you can set max lenght to 10 from variable's default value field -> Variable attributes : max_lenght=10



Capture.PNG



Thanks,


Joonas



please like or mark correct based on the impact of response


View solution in original post

11 REPLIES 11

joonas5
Kilo Expert

Hello Varun,



You can use single line text for mobile phone number variable.



Capture.PNG



Thanks,


Joonas


Hi Varun,



You can set min and max lenght from variable default value settings:



Capture.PNG



Thanks,


Joonas



please like or mark correct based on the impact of response


bvk
Kilo Contributor

but it should only accept integer and length of integer should be 10


You can use this an onchange client script to only accept numeric. If user is trying to write non numeric value then error occurs: Please enter numeric values only in the phone number field



function onChange(control, oldValue, newValue, isLoading) {  


    if (!isLoading) {  


          if(newValue != '') {  


                //check to see if there are any non numeric characters in the string  


                if(isNaN(newValue) == true) {  


                      alert("Please enter numeric values only in the phone number field");  


                      g_form.setValue('phone_number', '');  


    }  


  }  


}  


}  



And you can set max lenght to 10 from variable's default value field -> Variable attributes : max_lenght=10



Capture.PNG



Thanks,


Joonas



please like or mark correct based on the impact of response