To create a validation for your name field, type the following line into your and assign it the regex of any capital letter (A-Z), any lower case letter (a-z), a space, a hyphen or an apostrophe.
A much better way of solving this problem is to include inline validation that checks the user’s input as she progresses.
Another thing I like to do is to display the validation error message on the form in an otherwise hidden field: The problem with our last solution is that if the user saves a partially filled form, and picks it up at a later time, that error message that popped up is long gone, and the only indication that there is something wrong with the form is the modified field color.
So, having a text field contain that error message might be a good idea.
This alerts the user to any errors and allows her to correct her errors before proceeding and losing her progress.
As I mentioned before, information is passed to the validation function in the event object, and in the code we see that the member ‘value’ is used to communicate the current value of the field.