0

I have some input fields, which I want to validate directly as the user is typing

The input fields are bind to certain conditions though.

Here is the example:

<input type="text" data-type="inputFullName" />
<br />
<input type="text" data-type="inputEmail" />
<br />
<input type="text" data-type="inputPhone" />
<br / >
<input type="checkbox" id="chkbox" />
<label>Check here</label>
<br />
<button id="button1" disabled>Click</button>

And the JS:

$('input').on('keyup change', function () {
   $('#button1').prop('disabled', $('input[data-type="inputFullName"]').val() == '' || $('input[data-type="inputEmail"]').val() == '' || $('input[data-type="inputPhone"]').val() == '' || !$('input[type="checkbox"]').is(':checked'))
});

So far so good, but how can I check for:

1) user has entered full name (first+lastname)

2) email is actually an email

3) phonenumber is 8 numbers long

I have made an JSFiddle

Any help is appreciated.

ST80
  • 3,565
  • 16
  • 64
  • 124

1 Answers1

0

Email validation can be done by this: Validate email address in JavaScript?

phonenumber:

<input type="text" id="inputPhonenumber" >

js:

var phonenumber = document.getElementById("inputPhonenumber").value;
if(phonenumber.length == 8)
    return true;
else
    return false;

These questions have been answered before. And they are not that hard to find here.

Community
  • 1
  • 1
Wouter den Ouden
  • 1,523
  • 2
  • 17
  • 44