want to validate that a field can only contain numbers or floating point number

haider3
Kilo Contributor

I tried this code.

var regexp = new SNC.Regex('/^\d*\.?\d*/');

 

 

  var value1 = g_form.getValue('variables.rom');

  if(!regexp.match(value1))

  {

  alert('Only numbers and dot allowed');

  g_form.setValue('variables.rom','');

  }

But regexp.match(value1) always return true

3 REPLIES 3

Deepa Srivastav
Kilo Sage

Hi Haider,



Pelase try below:-



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


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


          return;


    }
var regexp = /^[0-9.]*$/;  
    if(!regexp.test(newValue))


{


  alert("Please enter only numbers");


  g_form.setValue('u_urfield, '');


  }


}



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Hi, thank you for your answer.

It also helped me.

Kind regards,

Natasha Machado

Deepa Srivastav
Kilo Sage

Let me know if you need any other assistance on this or mark the thread as closed to make it helpful for others in the future. You can find correct option by clicking on the below link.



want to validate that a field can only contain numbers or floating point number