The Zurich release has arrived! Interested in new features and functionalities? Click here for more

String field to accept only numeric values

shalinikacham
Kilo Expert

I have a string field but i should limit it such that only numeric values can be entered. Does anyone know how to do this?

1 ACCEPTED SOLUTION

Pradeep J
Kilo Guru

Hi Shalini ,



write a onChange(0 client script on field:



here I am explaning that EmpAge should read only digit not characters



i have field Empage of type strin but reads only digits



script:



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


    if (isLoading || newValue === '') {


          return;


    }




    //Type appropriate comment here, and begin script below


  var age=g_form.getValue('u_emp_age');



  if (isNaN(age))


    {


  alert("Age should be in Digits");


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


  return false;


    }


}



Thanks


Pradeep D J



PS - Please mark Helpful, Like, or Correct Answer if applicable.


View solution in original post

4 REPLIES 4

Deepak Kumar5
Kilo Sage

Write a Onchange Client Script to check the input using Use Reg Exp.



var str = g_form.getValue('field_name');


var regexp = /[0-9]/;


str.match(regexp);


Hi Deep



Where do i use this? Suppose my field name in 'number', where exactly should the above expression be given? Thanks for your help.


Pradeep J
Kilo Guru

Hi Shalini ,



write a onChange(0 client script on field:



here I am explaning that EmpAge should read only digit not characters



i have field Empage of type strin but reads only digits



script:



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


    if (isLoading || newValue === '') {


          return;


    }




    //Type appropriate comment here, and begin script below


  var age=g_form.getValue('u_emp_age');



  if (isNaN(age))


    {


  alert("Age should be in Digits");


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


  return false;


    }


}



Thanks


Pradeep D J



PS - Please mark Helpful, Like, or Correct Answer if applicable.