Code:
if (!/^[A-Z]/.test(username)) {
alert ("The user name must start with a capital letter");
return false;
}
if (/^\d{5}$/.test(field.value)) { /// match 5 digits and nothing but
if (/^\d{5}\-?\d{4}$/gi.test(field.value)) { // 5 digits, optional hyphen, 4 digits and nothing but
Bear in mind that if you require a zip code in USA format you will exclude non-US residents from whatever it is. That may be fine, of course.
You can automtically capitalise the first letter of each word in a string as follows:-
Code:
var str1 = "jEAn-paul o'flaNAGan-macDOnald";
str1 = str1.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()});
alert(str1);
But it would seem more important to ensure that a proper name consists only of letters, hyphen, apostrophe and possibly a space.
"Success is the ability to go from one failure to another with no loss of enthusiasm." - Sir Winston Churchill, British politician (1874 - 1965)