English subtitles

← Regex validation - Mobile Web Development

Get Embed Code
4 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. You may notice for some types like e-mail,
  2. there's some basic validation. But, it doesn't really understand.
  3. If you want to do better client side validation though,
  4. HTML-5 supports that too. There's also a pattern attribute on
  5. the input element, that you can use to validate on
  6. the client side. The pattern element takes a regular expression,
  7. as expressed by the java script regex syntax. Regex is
  8. a topic in itself. So, if you're not familiar with
  9. it, you'll have to look it up. For example, let's
  10. presume I want to only allow U.S. numbers with area
  11. code prefixes. So, an 11 digit number. I can put in a regular expression for
  12. this, and now when I try to input a telephone number and then submit, it
  13. pops up an error message that says I have to match the requested format. That
  14. error message, by the way, is the element's
  15. title, so you can customize it too. And
  16. now, I get my custom error message. Normally
  17. of course, I'm not going to want such a
  18. simplistic pattern. I'll probably going to want something more,
  19. like this string which says, I want a 3
  20. digit number possibly preceded by brackets, and then optionally
  21. a space or a period or a dash, and
  22. then another 3 digits, and then the same space
  23. or period or dash, and then another 4 digits.
  24. Now, this gives some options, for how I enter telephone
  25. numbers, but I can just say, and it'll accept that.