regex: i want to check for particular special characters from input using regex

SatheeshKumar
Kilo Sage

regex: i want to check for particular special characters from input using regex,thanks in advance

1 ACCEPTED SOLUTION

Hi Satheesh,



you want to restrict the below char.



[5/10/2017 8:08 PM] Eshwar Prasad Mallikarjun:


Disallow following special characters (&


[


]


~


@


|


$


^


<


>


\


*


+


=


;


?


`


')




if yes then please check with script below.




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


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


  return;


  }


  var specialCharRegex = /[~@|$^<>\*+=;?`')[\]]/;


  if(specialCharRegex.test(newValue)){


  alert('special chars are not allowed');


  g_form.setValue('<your field name where you are writing the special char>','');


  }


}



I have tested it in my PDI and it's working fine.




Thanks,


Harshvardhan




Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

12 REPLIES 12

try with below line



var regex = new RegExp("^[[ ] ~ @ | $ ^ < > \ * + = ; ? ` ')]*$");



thanks,


harshvardhan


Hi Satheesh,



you want to restrict the below char.



[5/10/2017 8:08 PM] Eshwar Prasad Mallikarjun:


Disallow following special characters (&


[


]


~


@


|


$


^


<


>


\


*


+


=


;


?


`


')




if yes then please check with script below.




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


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


  return;


  }


  var specialCharRegex = /[~@|$^<>\*+=;?`')[\]]/;


  if(specialCharRegex.test(newValue)){


  alert('special chars are not allowed');


  g_form.setValue('<your field name where you are writing the special char>','');


  }


}



I have tested it in my PDI and it's working fine.




Thanks,


Harshvardhan




Please Hit like, Helpful or Correct depending on the impact of the response


Hi Satheesh,



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



Thanks,


Harshvardhan