0

starting learning java html programming and need a bit of help for data validation in html forms.

Can anybody help out on the email pattern and the phone number data validation pls? Thanks heaps

// validating email pattern with @gmail.com

if (email.value.indexOf("@", 0) < 0) {
window.alert("Please enter a valid e-mail address.")
email.focus();
return false;
}

//validating phone number

if (phone.value =="//needs to be numbers only" ) {
window.alert("Please enter a valid phone number.")
phone.focus();
return false; }

Any assistance with email pattern and number validation would be great.

Frog
  • 1
  • you mean javascript, not java, right? – f.khantsis Apr 21 '19 at 09:38
  • Possible duplicate of [A comprehensive regex for phone number validation](https://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) – ayorgo Apr 21 '19 at 10:02

2 Answers2

0

Both of your problems are already asked here. You can find them by simply searching. or example take a look at these links link1 link2

Reza
  • 3,473
  • 4
  • 35
  • 54
0

don't mistake Java for JavaScript ! They're way not the same in use context, process or writing.... You can use HTML attributes such <input type="number"> to more and better checking(but that won't replace a check in the code) and/or attributes range , required. For string checks and finer checks you'll have to use regular expressions.

jean3xw
  • 121
  • 7