First of all, you shouldn't use
$('.submit').click()
but$('#myForm').submit()
as you will be able to submit forms by pressing enter too.To check if a string is a number, use
!isNan(string)
(see this answer this answer for more information).Email regex are difficult things. Just check if there is someting before the
@
(with.+?
) and if there is something after the@
(again with.+?
) and if that last part contains a.
and a couple of characters (from 2 to 6)It would make the function a lot easier if you put all specific code outside it. E.g:
validateForm({
'#nameInput': {
'valid': function (value) {
return /^[a-z]+$/i.test(value);
},
'label': '#nameLabel',
'messages': {
'empty': 'Please enter your name',
'invalid': 'Letters only',
},
},
'#companyInput': {
'label': '#companyLabel',
'messages': {
'empty': 'Please enter your company',
},
},
// ...
});
First of all, you shouldn't use
$('.submit').click()
but$('#myForm').submit()
as you will be able to submit forms by pressing enter too.To check if a string is a number, use
!isNan(string)
(see this answer for more information).Email regex are difficult things. Just check if there is someting before the
@
(with.+?
) and if there is something after the@
(again with.+?
) and if that last part contains a.
and a couple of characters (from 2 to 6)It would make the function a lot easier if you put all specific code outside it. E.g:
validateForm({
'#nameInput': {
'valid': function (value) {
return /^[a-z]+$/i.test(value);
},
'label': '#nameLabel',
'messages': {
'empty': 'Please enter your name',
'invalid': 'Letters only',
},
},
'#companyInput': {
'label': '#companyLabel',
'messages': {
'empty': 'Please enter your company',
},
},
// ...
});
First of all, you shouldn't use
$('.submit').click()
but$('#myForm').submit()
as you will be able to submit forms by pressing enter too.To check if a string is a number, use
!isNan(string)
(see this answer for more information).Email regex are difficult things. Just check if there is someting before the
@
(with.+?
) and if there is something after the@
(again with.+?
) and if that last part contains a.
and a couple of characters (from 2 to 6)It would make the function a lot easier if you put all specific code outside it. E.g:
validateForm({
'#nameInput': {
'valid': function (value) {
return /^[a-z]+$/i.test(value);
},
'label': '#nameLabel',
'messages': {
'empty': 'Please enter your name',
'invalid': 'Letters only',
},
},
'#companyInput': {
'label': '#companyLabel',
'messages': {
'empty': 'Please enter your company',
},
},
// ...
});
First of all, you shouldn't use
$('.submit').click()
but$('#myForm').submit()
as you will be able to submit forms by pressing enter too.To check if a string is a number, use
!isNan(string)
(see this answer for more information).Email regex are difficult things. Just check if there is someting before the
@
(with.+?
) and if there is something after the@
(again with.+?
) and if that last part contains a.
and a couple of characters (from 2 to 6)It would make the function a lot easier if you put all specific code outside it. E.g:
validateForm({
'#nameInput': {
'valid': function (value) {
return /^[a-z]+$/i.test(value);
},
'label': '#nameLabel',
'messages': {
'empty': 'Please enter your name',
'invalid': 'Letters only',
},
},
'#companyInput': {
'label': '#companyLabel',
'messages': {
'empty': 'Please enter your company',
},
},
// ...
});