regex - dutch 06 check


/ Published in: Regular Expression
Save to your folder(s)



Copy this code and paste it in your HTML
  1. checkPhone = '0a635++3Kjhsk9++87$%^&*(100.6'3=-2';
  2.  
  3. checkPhone.replace(/[^0-9]/g, '');
  4. //returns numbers
  5. //result: 06353987100632
  6.  
  7. checkPhone.replace(/[^\-;\+]/g, '');
  8. //returns + and -
  9. //result: ++++-
  10.  
  11. checkPhone.replace(/[0-9]/g, '');
  12. //removes 0-9
  13. //result: a++Kjhsk++$%^&*(.'=-
  14.  
  15. checkPhone.replace(/[0-9\-;\+]/g, '')
  16. //removes 0-9 and - and +
  17. //result: aKjhsk$%^&*(.'=
  18.  
  19.  
  20. //------------------------------OR TRY THIS------------------------------------
  21.  
  22. var error = false;
  23.  
  24. checkPhone = $.trim($('input#phone').val());
  25.  
  26. stripCheck = checkPhone.replace(/[0-9\-;\+]/g, '');
  27. if(stripCheck.length > 0) //checking for invalid chars (valid: 0-9, +, -)
  28. error = true; //console.log('invalid chars found');
  29.  
  30. numbers = checkPhone.replace(/[^0-9]/g, '');
  31. if(numbers.length < 10) //checking if there is atleast 10 digits
  32. error = true; //console.log('more then 10 digits pls');
  33.  
  34. if(checkPhone.replace(/[^\+]/g, '').length>1 || checkPhone.replace(/[^\-]/g, '').length>1) //there can be only one char of either + or -
  35. error = true; //console.log('too many + or -');
  36.  
  37. if(numbers.substr(0, 2) == '06' && numbers.length != 10) //if 06 it has to have 10 digits
  38. error = true; //console.log('06 error');
  39.  
  40. if(numbers.substr(0, 5) == '00316' && numbers.length != 13) //if 00316 it has to have 13 digits
  41. error = true; //console.log('00316 error');
  42.  
  43. if(checkPhone.substr(0, 4) == '+316' && numbers.length != 11) //if +316 it has to have 11 digits
  44. error = true; //console.log('316 error');
  45.  
  46. console.log(error);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.