regex.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. var numeric = '[0-9]+'
  2. var alphanumeric = '[A-Z $%*+\\-./:]+'
  3. var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
  4. '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
  5. '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
  6. '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'
  7. kanji = kanji.replace(/u/g, '\\u')
  8. var byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+'
  9. exports.KANJI = new RegExp(kanji, 'g')
  10. exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g')
  11. exports.BYTE = new RegExp(byte, 'g')
  12. exports.NUMERIC = new RegExp(numeric, 'g')
  13. exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g')
  14. var TEST_KANJI = new RegExp('^' + kanji + '$')
  15. var TEST_NUMERIC = new RegExp('^' + numeric + '$')
  16. var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$')
  17. exports.testKanji = function testKanji (str) {
  18. return TEST_KANJI.test(str)
  19. }
  20. exports.testNumeric = function testNumeric (str) {
  21. return TEST_NUMERIC.test(str)
  22. }
  23. exports.testAlphanumeric = function testAlphanumeric (str) {
  24. return TEST_ALPHANUMERIC.test(str)
  25. }