Check first character of a string


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.