Latin Characters check

前端 未结 3 2033
执念已碎
执念已碎 2021-01-05 09:16

there are some similar questions out there, but none that are quite the same or that have an answer that works for me.

I need a javascript function which validates w

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 09:42

    I'm using:

    /^[A-z\u00C0-\u00ff\s'\.,-\/#!$%\^&\*;:{}=\-_`~()]+$/
    

    as regular expression. I didn't test it with all the options but I've been using this for years and I never had any issue.

    var regexp = /[A-z\u00C0-\u00ff]+/g,
      ascii = ' hello !@#$%^&*())_+=',
      latin = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏàáâãäåæçèéêëìíîïÐÑÒÓÔÕÖØÙÚÛÜÝÞßðñòóôõöøùúûüýþÿ',
      chinese = ' 你 好 ';
    
    console.log(regexp.test(ascii)); // true
    console.log(regexp.test(latin)); // true
    console.log(regexp.test(chinese)); // false
    

    Glist: https://gist.github.com/germanattanasio/84cd25395688b7935182

提交回复
热议问题