最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript regex to reject non ASCII-US characters - Stack Overflow

programmeradmin3浏览0评论
^[^\x00-\x1F\x7F-\xFF]+$

This regex will properly fail to match a string that contains non-printing (hex 00-1f) or ASCII extended characters (hex 80-FF), but, unlike PHP, lets non-ASCII utf-8 characters pass. (eg. 日本واستقرارهहिन्दीދިވެހިބަސްગુજરાતી한)

Looking at the wikipedia page on UTF-8 all of those should fall in the 80-ff range. Does anyone know what I'm missing?

Also, if you could explain how to ignore quoted text, you would be my hero forever.

^[^\x00-\x1F\x7F-\xFF]+$

This regex will properly fail to match a string that contains non-printing (hex 00-1f) or ASCII extended characters (hex 80-FF), but, unlike PHP, lets non-ASCII utf-8 characters pass. (eg. 日本واستقرارهहिन्दीދިވެހިބަސްગુજરાતી한)

Looking at the wikipedia page on UTF-8 all of those should fall in the 80-ff range. Does anyone know what I'm missing?

Also, if you could explain how to ignore quoted text, you would be my hero forever.

Share Improve this question edited Aug 12, 2010 at 8:34 Greg asked Aug 12, 2010 at 8:23 GregGreg 7,9228 gold badges45 silver badges69 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Hmm... instead of rejecting byte ranges, try matching actual Unicode characters, e.g.:

^[\u0020-\u007e]+$
发布评论

评论列表(0)

  1. 暂无评论