Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  • 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',
 },
 },
 // ...
 });
Source Link
Wouter J
  • 657
  • 3
  • 10
  • 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',
 },
 },
 // ...
 });
default

AltStyle によって変換されたページ (->オリジナル) /