The CreatorCon Call for Content is officially open! Get started here.

Regular expression to restrict 20 characters in single line text variable

Rajesh Mushke
Mega Sage

HI All,

I need help to build regular expression to restrict enter 20 numbers & below characters in single line text.

20 Numeric and only the special characters that include: + ( ) - 

 

Thanks in advance.!

 

Thanks,

Rajashekhar Mushke



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
17 REPLIES 17

Hi Asifnoor

 
Not working

 

Thanks,

Rajashekhar Mushke



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Hi Asif,

 

Not working



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Can you tell me which case is failing? and how you are testing this code?

Hi Asif,

 

Here is my client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var pattern =/^[0-9-+()]{1,20}$/;


if(!pattern.test(newValue)){


alert('Phone enter a valid Contact number');


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


}
}

 

Thanks,

Rajashekhar Mushke



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Hi,

I just tried with this code on incident table and hsort_description field and it seems to be working fine. Just verify in your code, if it is entering onchange or not. If entered, then check whether its entering the if conditon or not.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	alert("test");
   //Type appropriate comment here, and begin script below
   var pattern =/^[0-9-+()]{1,20}$/;
   if(!pattern.test(newValue)){
     alert('Phone enter a valid Contact number');
     g_form.setValue('short_description', '');
   }
}

Mark the comment as a correct answer and also helpful once worked.