Text box allow alphanumeric it accepts only 4 digits?

Shantharao
Kilo Sage

Hello All,

I have a requirement like, single line textbox allow alphanumerics only, it restricts for only 4 digits combination alphanumeric, if user enters more than 4 digits it will show field error message like "it accepts only 4 digits or character"

find_real_file.png

I have written below script it does not as I expected

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

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

  return;

  }

  var subject = g_form.getValue('name'_var);

  var regexp = /^[a-zA-Z0-9.]*$/; // accept 0 to 9 numbers only

  if(!regexp.test(newValue) || subject>9999 || subject>zzzz )

  {

  g_form.showFieldMsg('name_var','Please enter only 4 digits','error');

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

  }

  //Type appropriate comment here, and begin script below

}

Can any one help on this requirement

Thank you

1 ACCEPTED SOLUTION

souren0071
Tera Expert

Hi Burra,



Create one onchange client script and use this below code for this requirement:



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


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


  return;


  }


  var letterNumber = /^[0-9a-zA-Z]+$/;


  if(!(newValue.match(letterNumber)) || newValue.toString().length>4)


  alert('It accepts only 4 digits or character');


  }


//Type appropriate comment here, and begin script below



Regards,


Souren


Hit correct/helpful based on impact.


View solution in original post

2 REPLIES 2

souren0071
Tera Expert

Hi Burra,



Create one onchange client script and use this below code for this requirement:



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


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


  return;


  }


  var letterNumber = /^[0-9a-zA-Z]+$/;


  if(!(newValue.match(letterNumber)) || newValue.toString().length>4)


  alert('It accepts only 4 digits or character');


  }


//Type appropriate comment here, and begin script below



Regards,


Souren


Hit correct/helpful based on impact.


g_form.showFieldMsg('short_description',"It accepts only 4 digits or character.",'error'); can be replaced with the alert statement.