code_junkie

Javascript Regular Expressions - Required field validation

Nov 12th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. if (myField.value.match(/S/)) {
  2. // field is not empty
  3. }
  4.  
  5. /^s*$/.test(string)
  6.  
  7. var empty_string = /^s*$/; //create RegExp object for re-use
  8.  
  9. if (empty_string.test(myFormField.value))
  10. {
  11. alert("Please be a bit more elaborate!");
  12. }
  13.  
  14. /s/ or /S/
  15.  
  16. /^s+$/ or /^S+$/
  17.  
  18. if(string.match(/^s+$/)) {
  19. alert("string is empty!");
  20. }
  21.  
  22. if(!string.match(/^S+$/)) {
  23. alert("string is empty!");
  24. }
Add Comment
Please, Sign In to add comment