Posted By

haoming on 12/16/07


Tagged


Versions (?)

test the string contain chinese words


 / Published in: JavaScript
 

  1. 檢查中文字
  2. <form name="form1">
  3. <input id="text1" type="text" name="text1" value="123" size="10">
  4. <input type="button" name="btn1" value="click me" onClick="chkword()">
  5. </form>
  6. <script type="text/javascript">
  7.  
  8. function chkword(){
  9. alert (ischinese(document.form1.text1.value));
  10. }
  11.  
  12. function ischinese(s){
  13. var ret=true;
  14. for(var i=0;i<s.length;i++)
  15. ret=ret && (s.charCodeAt(i)>=10000);
  16. return ret;
  17. }
  18.  
  19. </script>

Report this snippet  

You need to login to post a comment.