Posted By

NyX on 09/01/09


Tagged

check character String first


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

brianyang


Check first character of a string


 / Published in: JavaScript
 

Checks if the first char of a string is a : letter, number, dot ( . ), arond ( @ ), underscore ( _ ).

  1. function isLetter($a) {
  2. $inta=$a.charCodeAt('0');
  3. if($inta>=97&&$inta<=122)
  4. return true;
  5. return false;
  6. }
  7.  
  8. function isNumber($a) {
  9. $inta=$a.charCodeAt('0');
  10. if($inta>=48&&$inta<=57)
  11. return true;
  12. return false;
  13. }
  14.  
  15. function isDot($a) {
  16. if($a.charCodeAt('0')==46)
  17. return true;
  18. return false;
  19. }
  20.  
  21. function isArond($a) {
  22. if($a.charCodeAt('0')==64)
  23. return true;
  24. return false;
  25. }
  26.  
  27. function isUnderscore($a) {
  28. if($a.charCodeAt('0')==95)
  29. return true;
  30. return false;
  31. }

Report this snippet  

You need to login to post a comment.