Match kanji character - Node.js String

Node.js examples for String:Char

Description

Match kanji character

Demo Code

// matches a single kanji character
String.prototype.isaKanji = function(){
  return !!this.match(/^[\u4E00-\u9FAF]$/);
}

// matches one or more kanji characters
String.prototype.isKanji = function(){
  return !!this.match(/^[\u4E00-\u9FAF]+$/);
}

//check if there's kanji in the string
String.prototype.hasKanji = function(){
  return !!this.match(/[\u4E00-\u9FAF]/);
}

Related Tutorials