Simplify form validation with function
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
In jQuery, I have been reluctant to create a better form validation, and I feel the time has come for me to do so.
With that said, I have been using this particular type of form validation, and I would like to simplify it.
$('#saveSubmit').on('click', function()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
// form validation starts here
if(criteria.company == "")
$('#compError').show();
return false;
if(criteria.partnercode == "")
$('#compError').show();
return false;
if(criteria.office == "")
$('#compError').show();
return false;
// few more if statements
else
// if the form parameters are good, send to processing script
$.post('process/editUser.php', criteria:criteria, function(data)
if(data.indexOf("Error") >= 0)
$('#errorModal').modal('show');
$('#message').text(data);
return false;
else
$('#successModal').modal('show');
$('#messageSuccess').text(data);
$('#successModal').on('hidden.bs.modal', function()
$('#successModal').modal('hide');
location.reload();
);
);
);
All of this works like how it should, but I want to make it less verbose, thus the need for a function.
I want to replace that huge if
/else
statement within that click event with a function.
javascript jquery functional-programming validation
add a comment |Â
up vote
3
down vote
favorite
In jQuery, I have been reluctant to create a better form validation, and I feel the time has come for me to do so.
With that said, I have been using this particular type of form validation, and I would like to simplify it.
$('#saveSubmit').on('click', function()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
// form validation starts here
if(criteria.company == "")
$('#compError').show();
return false;
if(criteria.partnercode == "")
$('#compError').show();
return false;
if(criteria.office == "")
$('#compError').show();
return false;
// few more if statements
else
// if the form parameters are good, send to processing script
$.post('process/editUser.php', criteria:criteria, function(data)
if(data.indexOf("Error") >= 0)
$('#errorModal').modal('show');
$('#message').text(data);
return false;
else
$('#successModal').modal('show');
$('#messageSuccess').text(data);
$('#successModal').on('hidden.bs.modal', function()
$('#successModal').modal('hide');
location.reload();
);
);
);
All of this works like how it should, but I want to make it less verbose, thus the need for a function.
I want to replace that huge if
/else
statement within that click event with a function.
javascript jquery functional-programming validation
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
In jQuery, I have been reluctant to create a better form validation, and I feel the time has come for me to do so.
With that said, I have been using this particular type of form validation, and I would like to simplify it.
$('#saveSubmit').on('click', function()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
// form validation starts here
if(criteria.company == "")
$('#compError').show();
return false;
if(criteria.partnercode == "")
$('#compError').show();
return false;
if(criteria.office == "")
$('#compError').show();
return false;
// few more if statements
else
// if the form parameters are good, send to processing script
$.post('process/editUser.php', criteria:criteria, function(data)
if(data.indexOf("Error") >= 0)
$('#errorModal').modal('show');
$('#message').text(data);
return false;
else
$('#successModal').modal('show');
$('#messageSuccess').text(data);
$('#successModal').on('hidden.bs.modal', function()
$('#successModal').modal('hide');
location.reload();
);
);
);
All of this works like how it should, but I want to make it less verbose, thus the need for a function.
I want to replace that huge if
/else
statement within that click event with a function.
javascript jquery functional-programming validation
In jQuery, I have been reluctant to create a better form validation, and I feel the time has come for me to do so.
With that said, I have been using this particular type of form validation, and I would like to simplify it.
$('#saveSubmit').on('click', function()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
// form validation starts here
if(criteria.company == "")
$('#compError').show();
return false;
if(criteria.partnercode == "")
$('#compError').show();
return false;
if(criteria.office == "")
$('#compError').show();
return false;
// few more if statements
else
// if the form parameters are good, send to processing script
$.post('process/editUser.php', criteria:criteria, function(data)
if(data.indexOf("Error") >= 0)
$('#errorModal').modal('show');
$('#message').text(data);
return false;
else
$('#successModal').modal('show');
$('#messageSuccess').text(data);
$('#successModal').on('hidden.bs.modal', function()
$('#successModal').modal('hide');
location.reload();
);
);
);
All of this works like how it should, but I want to make it less verbose, thus the need for a function.
I want to replace that huge if
/else
statement within that click event with a function.
javascript jquery functional-programming validation
edited May 15 at 2:33
Jamalâ¦
30.1k11114225
30.1k11114225
asked May 14 at 15:39
John Beasley
1704
1704
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
4
down vote
You might break apart the code in separate functions, and create a function that opens and closes a modal with a custom text. I didn't check this code, hopefully you get some ideas for improvement!
$('#saveSubmit').on('click',()=>validateForm())
function validateForm()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
let error = ""
if(criteria.company == "")
error += "No company specified";
if(criteria.partnercode == "")
error += "No partner code specified";
if(error == "")
postData(criteria);
else
showModal(error);
function postData(criteria)
$.post('process/editUser.php', criteria:criteria,(data)=>checkData())
function checkData(data)
if(data.indexOf("Error") >= 0)
showModal("error " + data, false);
else
showModal("data posted!", true);
function showModal(content, button)
$('#modal').show();
$('#message').text(content);
if(button)
$('#modalbutton').show();
$('#modalbutton').on('click',() => hideModal());
function hideModal
$('#modal').hide();
add a comment |Â
up vote
4
down vote
The obvious improvement to make it less verbose, if all your if
statement just check an empty string (that's why it's asked to post all your code here btw ^^), is to use a loop instead, for example :
for(let attr in criteria)
if(criteria[attr] == "")
$('#compError').show();
return false;
Also, since return false;
shut the current function execution, you don't need an else
around your $post
(and it wouldn't fit with this new loop system anyway).
add a comment |Â
up vote
2
down vote
You can set a class for each field that is required. Then, on form validate, loop through all the required fields. If you find one that is empty, go into your routine. Here's an example, which assumes that all required elements have the class required
:
function validate()
var q = document.querySelectorAll('.required');
for (var i=0; i<q.length; i++)
if ('' == q[i].value)
$('#compError').show();
return false;
return true;
From a UX standpoint, I would consider focusing on the offending element, and showing a message saying that the specific field is required.
add a comment |Â
up vote
2
down vote
The question originally was tagged with functional-programming, but it seems more declarative/procedural than functional, other than the fact that callback functions are passed to the click handlers.
The answer by Nomis is good: one can iterate over the values in criteria and as soon as a blank value is found, show the error message container. A functional approach for this would be to use Object.values() to get the array of values in criteria
and then utilize Array.every() to look for empty values:
var allNonEmpty = Object.values(criteria).every(function(entry)
return entry.length;
);
if (!allNonEmpty)
$('#compError').show();
If you are supporting ES-2015 (A.K.A. es-6) then an arrow function can make that shorter:
const allNonEmpty = Object.values(criteria).every(entry => entry.length);
It is also advisable to cache DOM lookups instead of performing them each time. So when the page loads, it might be best to store a reference to each input in a variable (or, if using es-6, a constant using const
). See the expandable snippet below for an example.
$(function() //jQuery DOM-ready callback
var inputFields =
company: $('#company'),
partnercode: $('#partnercode'),
office: $('#office')
;
var compError = $('#compError');
$('#saveSubmit').on('click', function()
var allNonEmpty = Object.values(inputFields).every(function(inputField)
return $(inputField).val().length;
);
if (!allNonEmpty)
compError.show();
return;
else
compError.hide();
//AJAX code
);
);
.hidden
display: none;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="banner-message">
<pThe Form</p>
<div>
Company: <input id="company" />
</div>
<div>
Partner: <input id="partnercode" />
</div>
<div>
office: <input id="office" />
</div>
<button id="saveSubmit">submit</button>
<div id="compError" class="hidden">
Error!
</div>
</div>
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You might break apart the code in separate functions, and create a function that opens and closes a modal with a custom text. I didn't check this code, hopefully you get some ideas for improvement!
$('#saveSubmit').on('click',()=>validateForm())
function validateForm()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
let error = ""
if(criteria.company == "")
error += "No company specified";
if(criteria.partnercode == "")
error += "No partner code specified";
if(error == "")
postData(criteria);
else
showModal(error);
function postData(criteria)
$.post('process/editUser.php', criteria:criteria,(data)=>checkData())
function checkData(data)
if(data.indexOf("Error") >= 0)
showModal("error " + data, false);
else
showModal("data posted!", true);
function showModal(content, button)
$('#modal').show();
$('#message').text(content);
if(button)
$('#modalbutton').show();
$('#modalbutton').on('click',() => hideModal());
function hideModal
$('#modal').hide();
add a comment |Â
up vote
4
down vote
You might break apart the code in separate functions, and create a function that opens and closes a modal with a custom text. I didn't check this code, hopefully you get some ideas for improvement!
$('#saveSubmit').on('click',()=>validateForm())
function validateForm()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
let error = ""
if(criteria.company == "")
error += "No company specified";
if(criteria.partnercode == "")
error += "No partner code specified";
if(error == "")
postData(criteria);
else
showModal(error);
function postData(criteria)
$.post('process/editUser.php', criteria:criteria,(data)=>checkData())
function checkData(data)
if(data.indexOf("Error") >= 0)
showModal("error " + data, false);
else
showModal("data posted!", true);
function showModal(content, button)
$('#modal').show();
$('#message').text(content);
if(button)
$('#modalbutton').show();
$('#modalbutton').on('click',() => hideModal());
function hideModal
$('#modal').hide();
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You might break apart the code in separate functions, and create a function that opens and closes a modal with a custom text. I didn't check this code, hopefully you get some ideas for improvement!
$('#saveSubmit').on('click',()=>validateForm())
function validateForm()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
let error = ""
if(criteria.company == "")
error += "No company specified";
if(criteria.partnercode == "")
error += "No partner code specified";
if(error == "")
postData(criteria);
else
showModal(error);
function postData(criteria)
$.post('process/editUser.php', criteria:criteria,(data)=>checkData())
function checkData(data)
if(data.indexOf("Error") >= 0)
showModal("error " + data, false);
else
showModal("data posted!", true);
function showModal(content, button)
$('#modal').show();
$('#message').text(content);
if(button)
$('#modalbutton').show();
$('#modalbutton').on('click',() => hideModal());
function hideModal
$('#modal').hide();
You might break apart the code in separate functions, and create a function that opens and closes a modal with a custom text. I didn't check this code, hopefully you get some ideas for improvement!
$('#saveSubmit').on('click',()=>validateForm())
function validateForm()
var criteria =
company: $('#company').val(),
partnercode: $('#partnercode').val(),
office: $('#office').val(),
// few more
let error = ""
if(criteria.company == "")
error += "No company specified";
if(criteria.partnercode == "")
error += "No partner code specified";
if(error == "")
postData(criteria);
else
showModal(error);
function postData(criteria)
$.post('process/editUser.php', criteria:criteria,(data)=>checkData())
function checkData(data)
if(data.indexOf("Error") >= 0)
showModal("error " + data, false);
else
showModal("data posted!", true);
function showModal(content, button)
$('#modal').show();
$('#message').text(content);
if(button)
$('#modalbutton').show();
$('#modalbutton').on('click',() => hideModal());
function hideModal
$('#modal').hide();
answered May 14 at 15:57
Kokodoko
1815
1815
add a comment |Â
add a comment |Â
up vote
4
down vote
The obvious improvement to make it less verbose, if all your if
statement just check an empty string (that's why it's asked to post all your code here btw ^^), is to use a loop instead, for example :
for(let attr in criteria)
if(criteria[attr] == "")
$('#compError').show();
return false;
Also, since return false;
shut the current function execution, you don't need an else
around your $post
(and it wouldn't fit with this new loop system anyway).
add a comment |Â
up vote
4
down vote
The obvious improvement to make it less verbose, if all your if
statement just check an empty string (that's why it's asked to post all your code here btw ^^), is to use a loop instead, for example :
for(let attr in criteria)
if(criteria[attr] == "")
$('#compError').show();
return false;
Also, since return false;
shut the current function execution, you don't need an else
around your $post
(and it wouldn't fit with this new loop system anyway).
add a comment |Â
up vote
4
down vote
up vote
4
down vote
The obvious improvement to make it less verbose, if all your if
statement just check an empty string (that's why it's asked to post all your code here btw ^^), is to use a loop instead, for example :
for(let attr in criteria)
if(criteria[attr] == "")
$('#compError').show();
return false;
Also, since return false;
shut the current function execution, you don't need an else
around your $post
(and it wouldn't fit with this new loop system anyway).
The obvious improvement to make it less verbose, if all your if
statement just check an empty string (that's why it's asked to post all your code here btw ^^), is to use a loop instead, for example :
for(let attr in criteria)
if(criteria[attr] == "")
$('#compError').show();
return false;
Also, since return false;
shut the current function execution, you don't need an else
around your $post
(and it wouldn't fit with this new loop system anyway).
answered May 14 at 16:00
Nomis
1615
1615
add a comment |Â
add a comment |Â
up vote
2
down vote
You can set a class for each field that is required. Then, on form validate, loop through all the required fields. If you find one that is empty, go into your routine. Here's an example, which assumes that all required elements have the class required
:
function validate()
var q = document.querySelectorAll('.required');
for (var i=0; i<q.length; i++)
if ('' == q[i].value)
$('#compError').show();
return false;
return true;
From a UX standpoint, I would consider focusing on the offending element, and showing a message saying that the specific field is required.
add a comment |Â
up vote
2
down vote
You can set a class for each field that is required. Then, on form validate, loop through all the required fields. If you find one that is empty, go into your routine. Here's an example, which assumes that all required elements have the class required
:
function validate()
var q = document.querySelectorAll('.required');
for (var i=0; i<q.length; i++)
if ('' == q[i].value)
$('#compError').show();
return false;
return true;
From a UX standpoint, I would consider focusing on the offending element, and showing a message saying that the specific field is required.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You can set a class for each field that is required. Then, on form validate, loop through all the required fields. If you find one that is empty, go into your routine. Here's an example, which assumes that all required elements have the class required
:
function validate()
var q = document.querySelectorAll('.required');
for (var i=0; i<q.length; i++)
if ('' == q[i].value)
$('#compError').show();
return false;
return true;
From a UX standpoint, I would consider focusing on the offending element, and showing a message saying that the specific field is required.
You can set a class for each field that is required. Then, on form validate, loop through all the required fields. If you find one that is empty, go into your routine. Here's an example, which assumes that all required elements have the class required
:
function validate()
var q = document.querySelectorAll('.required');
for (var i=0; i<q.length; i++)
if ('' == q[i].value)
$('#compError').show();
return false;
return true;
From a UX standpoint, I would consider focusing on the offending element, and showing a message saying that the specific field is required.
answered May 19 at 20:51
BobRodes
1212
1212
add a comment |Â
add a comment |Â
up vote
2
down vote
The question originally was tagged with functional-programming, but it seems more declarative/procedural than functional, other than the fact that callback functions are passed to the click handlers.
The answer by Nomis is good: one can iterate over the values in criteria and as soon as a blank value is found, show the error message container. A functional approach for this would be to use Object.values() to get the array of values in criteria
and then utilize Array.every() to look for empty values:
var allNonEmpty = Object.values(criteria).every(function(entry)
return entry.length;
);
if (!allNonEmpty)
$('#compError').show();
If you are supporting ES-2015 (A.K.A. es-6) then an arrow function can make that shorter:
const allNonEmpty = Object.values(criteria).every(entry => entry.length);
It is also advisable to cache DOM lookups instead of performing them each time. So when the page loads, it might be best to store a reference to each input in a variable (or, if using es-6, a constant using const
). See the expandable snippet below for an example.
$(function() //jQuery DOM-ready callback
var inputFields =
company: $('#company'),
partnercode: $('#partnercode'),
office: $('#office')
;
var compError = $('#compError');
$('#saveSubmit').on('click', function()
var allNonEmpty = Object.values(inputFields).every(function(inputField)
return $(inputField).val().length;
);
if (!allNonEmpty)
compError.show();
return;
else
compError.hide();
//AJAX code
);
);
.hidden
display: none;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="banner-message">
<pThe Form</p>
<div>
Company: <input id="company" />
</div>
<div>
Partner: <input id="partnercode" />
</div>
<div>
office: <input id="office" />
</div>
<button id="saveSubmit">submit</button>
<div id="compError" class="hidden">
Error!
</div>
</div>
add a comment |Â
up vote
2
down vote
The question originally was tagged with functional-programming, but it seems more declarative/procedural than functional, other than the fact that callback functions are passed to the click handlers.
The answer by Nomis is good: one can iterate over the values in criteria and as soon as a blank value is found, show the error message container. A functional approach for this would be to use Object.values() to get the array of values in criteria
and then utilize Array.every() to look for empty values:
var allNonEmpty = Object.values(criteria).every(function(entry)
return entry.length;
);
if (!allNonEmpty)
$('#compError').show();
If you are supporting ES-2015 (A.K.A. es-6) then an arrow function can make that shorter:
const allNonEmpty = Object.values(criteria).every(entry => entry.length);
It is also advisable to cache DOM lookups instead of performing them each time. So when the page loads, it might be best to store a reference to each input in a variable (or, if using es-6, a constant using const
). See the expandable snippet below for an example.
$(function() //jQuery DOM-ready callback
var inputFields =
company: $('#company'),
partnercode: $('#partnercode'),
office: $('#office')
;
var compError = $('#compError');
$('#saveSubmit').on('click', function()
var allNonEmpty = Object.values(inputFields).every(function(inputField)
return $(inputField).val().length;
);
if (!allNonEmpty)
compError.show();
return;
else
compError.hide();
//AJAX code
);
);
.hidden
display: none;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="banner-message">
<pThe Form</p>
<div>
Company: <input id="company" />
</div>
<div>
Partner: <input id="partnercode" />
</div>
<div>
office: <input id="office" />
</div>
<button id="saveSubmit">submit</button>
<div id="compError" class="hidden">
Error!
</div>
</div>
add a comment |Â
up vote
2
down vote
up vote
2
down vote
The question originally was tagged with functional-programming, but it seems more declarative/procedural than functional, other than the fact that callback functions are passed to the click handlers.
The answer by Nomis is good: one can iterate over the values in criteria and as soon as a blank value is found, show the error message container. A functional approach for this would be to use Object.values() to get the array of values in criteria
and then utilize Array.every() to look for empty values:
var allNonEmpty = Object.values(criteria).every(function(entry)
return entry.length;
);
if (!allNonEmpty)
$('#compError').show();
If you are supporting ES-2015 (A.K.A. es-6) then an arrow function can make that shorter:
const allNonEmpty = Object.values(criteria).every(entry => entry.length);
It is also advisable to cache DOM lookups instead of performing them each time. So when the page loads, it might be best to store a reference to each input in a variable (or, if using es-6, a constant using const
). See the expandable snippet below for an example.
$(function() //jQuery DOM-ready callback
var inputFields =
company: $('#company'),
partnercode: $('#partnercode'),
office: $('#office')
;
var compError = $('#compError');
$('#saveSubmit').on('click', function()
var allNonEmpty = Object.values(inputFields).every(function(inputField)
return $(inputField).val().length;
);
if (!allNonEmpty)
compError.show();
return;
else
compError.hide();
//AJAX code
);
);
.hidden
display: none;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="banner-message">
<pThe Form</p>
<div>
Company: <input id="company" />
</div>
<div>
Partner: <input id="partnercode" />
</div>
<div>
office: <input id="office" />
</div>
<button id="saveSubmit">submit</button>
<div id="compError" class="hidden">
Error!
</div>
</div>
The question originally was tagged with functional-programming, but it seems more declarative/procedural than functional, other than the fact that callback functions are passed to the click handlers.
The answer by Nomis is good: one can iterate over the values in criteria and as soon as a blank value is found, show the error message container. A functional approach for this would be to use Object.values() to get the array of values in criteria
and then utilize Array.every() to look for empty values:
var allNonEmpty = Object.values(criteria).every(function(entry)
return entry.length;
);
if (!allNonEmpty)
$('#compError').show();
If you are supporting ES-2015 (A.K.A. es-6) then an arrow function can make that shorter:
const allNonEmpty = Object.values(criteria).every(entry => entry.length);
It is also advisable to cache DOM lookups instead of performing them each time. So when the page loads, it might be best to store a reference to each input in a variable (or, if using es-6, a constant using const
). See the expandable snippet below for an example.
$(function() //jQuery DOM-ready callback
var inputFields =
company: $('#company'),
partnercode: $('#partnercode'),
office: $('#office')
;
var compError = $('#compError');
$('#saveSubmit').on('click', function()
var allNonEmpty = Object.values(inputFields).every(function(inputField)
return $(inputField).val().length;
);
if (!allNonEmpty)
compError.show();
return;
else
compError.hide();
//AJAX code
);
);
.hidden
display: none;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="banner-message">
<pThe Form</p>
<div>
Company: <input id="company" />
</div>
<div>
Partner: <input id="partnercode" />
</div>
<div>
office: <input id="office" />
</div>
<button id="saveSubmit">submit</button>
<div id="compError" class="hidden">
Error!
</div>
</div>
$(function() //jQuery DOM-ready callback
var inputFields =
company: $('#company'),
partnercode: $('#partnercode'),
office: $('#office')
;
var compError = $('#compError');
$('#saveSubmit').on('click', function()
var allNonEmpty = Object.values(inputFields).every(function(inputField)
return $(inputField).val().length;
);
if (!allNonEmpty)
compError.show();
return;
else
compError.hide();
//AJAX code
);
);
.hidden
display: none;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="banner-message">
<pThe Form</p>
<div>
Company: <input id="company" />
</div>
<div>
Partner: <input id="partnercode" />
</div>
<div>
office: <input id="office" />
</div>
<button id="saveSubmit">submit</button>
<div id="compError" class="hidden">
Error!
</div>
</div>
$(function() //jQuery DOM-ready callback
var inputFields =
company: $('#company'),
partnercode: $('#partnercode'),
office: $('#office')
;
var compError = $('#compError');
$('#saveSubmit').on('click', function()
var allNonEmpty = Object.values(inputFields).every(function(inputField)
return $(inputField).val().length;
);
if (!allNonEmpty)
compError.show();
return;
else
compError.hide();
//AJAX code
);
);
.hidden
display: none;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="banner-message">
<pThe Form</p>
<div>
Company: <input id="company" />
</div>
<div>
Partner: <input id="partnercode" />
</div>
<div>
office: <input id="office" />
</div>
<button id="saveSubmit">submit</button>
<div id="compError" class="hidden">
Error!
</div>
</div>
edited May 19 at 23:09
answered May 14 at 21:08
Sam Onela
5,77461543
5,77461543
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194368%2fsimplify-form-validation-with-function%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password