jQuery Regex for International Characters

Hi

I am trying to validate a textarea text field for international characters (i.e. Japanese, Chinese, Urdu, French, English etc etc).

I am doing a validation script in jQuery file for a HTML field.

var regEx = / insert something in here /;

var tx = $('textarea');
for (var x = 0;  x < tx.length; x++){
{
    if (  !regEx.test(  tx.eq(x).val()  ) )
   {
      console.log('regex failed');
   } else console.log('regex ok');
}

Getting that regEx is proving to be a little tricky as some regEx appear to be language specific? Any suggestions on a jQuery RegEx for the above code?
thx!
Karen

You don’t have to use regex if it’s not suitable. What are your requirements for what’s allowed in the textarea?

Hi Paul

It’s a description area where customers describe a service they want.

I want to allow all international languages but no “harmful” characters (pardon as I am not entirely sure what those are) I am thinking no < > but otherwise any guidance as to alternative to regex or pointers as to what to strip out (maybe Html entities in php) or a good way to sanitize the data would be helpful for jQuery.

Thanks!
Karen

< > ( ) = & should take care of most malicious code, tbh.

Ok looking at a site wholistically

(I am using a LEMP stack)

Is ALL malicious code on jQuery reasonable or do we get it at php with regex?

Sorry, I am not sure what to do with the description “most malicious code”.

Thanks!

Personally I wouldn’t worry all that much about using JavaScript to sanitize user input in the browser client-side. Validate to help catch honest mistakes, yes, but a malicious user can easily “unsanitize” the input.

Cool! Yes that makes sense :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.