Jump to content

Validation String question


Webmaster001

Recommended Posts

We have a custom field that is a "Name" for example Jack Smith. We want to set " Expression Validation String" so it checks whether the typed name matches this format.

 

Name Lastname (only characters and it should not be empty). We used the following:

 

/^[a-z\d_]{2,28}$/i

 

However this does allow empty fields to be submitted. Any suggestion what validation string we should use to check for empty fields and allows spaces?

Link to comment
Share on other sites

I think the regex below would be valid - though depending on what you need it for, it might be overkill !

 

it allows characters, apostrophes (e.g Irish type names O'Smith) and double-barrel names (John Smith-Jones)

 

/^([a-zA-Z'-]+\s?){1,4}[a-zA-z'-]+$/

 

although it's not perfect as it would allow multiple hyphens or apostrophes, and wouldn't allow international names and characters (ć etc)

Link to comment
Share on other sites

aahh it was late at night! :oops:

 

in this instance, there's no need to check for an empty string - go back to the original regex below and make it a "Required Field" in the custom fields tab of the product - that will prevent it from being empty, and the regex should keep it to a valid format.

 

/^([a-zA-Z'-]+\s?){1,4}[a-zA-z'-]+$/
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated