Jump to content

Regular Expression Validation String


mec

Recommended Posts

Hi

 

Under your admin area under setup there is an option for Custom Client Fields, you can use this to add custom field to your client area, invoices and order form.

 

For example say you would like to get your clients VAT/TAX Number you can create an field for it and have them fill it in on the order form.

 

You can also use these fields on your PDF/HTML Invoices for example on the pdf invoice you will include it as $clientsdetails["customfieldsx"], remember that x is the number of your custom field.

 

Thanks

 

Computers Wheneva

http://www.wheneva.co.za

Link to comment
Share on other sites

The Regular Expression Validation String is a string of characters that is used to check (validate) the contents of the custom field.

 

In other words, whenever an entry is made into the custom field, you can either just accept what is typed in as it is entered, or using a Regular Expression Validation String, check it to see if it’s in the right format.

 

In truth, it’s not really that important and you could leave the validation field empty for most stuff if it’s just information that you don’t need to use later for calculating or formatting.

 

If it’s not important then why bother?

You would use validation strings to ensure that the data entered is in a format you want.

If it does not matter then you can ignore it. Though having said that it’s probably a good idea to limit entries to only letters and numbers (see later)

Simple example.

Maybe you want users to enter a number (maybe a product or quantity a special code). You need to ensure all characters are just numbers, with no other stuff.

So, you create your custom field without any validation and put a note to the client to only enter numbers. How difficult could that be?

They enter: 12O.

But then later, you want to use that figure and add 1 to it (to make it 121) and its not working.

You wonder what could be wrong?

 

What is wrong is that the O is in fact an O, not a zero. And that breaks any calculations.

 

Its a lot easier to use a simple Regular Expression Validation String (usually shortened to RegEx) to check what is entered and warn the client if it’s wrong.

 

In the above example we want them to only enter numerals.

 

Here is what you would put in the Regular Expression Validation String box to only allow numerals:

 

^[0-9]*$

 

Here is another example which requires at least one numeral, but no more than three:

 

[0-9]{1,3}

 

Finally, as I mentioned earlier, you probably want to at least ensure the custom fields only contain alpha or numeric characters.

Here a RegEx expression to do that.

 

^[A-Za-z0-9]

 

This one allows you spaces as well.

 

^[a-zA-Z0-9 ]*$

 

Trevor

Link to comment
Share on other sites

  • 10 years later...
On 4/23/2011 at 4:24 AM, sohouk said:

The Regular Expression Validation String is a string of characters that is used to check (validate) the contents of the custom field.

 

In other words, whenever an entry is made into the custom field, you can either just accept what is typed in as it is entered, or using a Regular Expression Validation String, check it to see if it’s in the right format.

 

In truth, it’s not really that important and you could leave the validation field empty for most stuff if it’s just information that you don’t need to use later for calculating or formatting.

 

If it’s not important then why bother?

You would use validation strings to ensure that the data entered is in a format you want.

If it does not matter then you can ignore it. Though having said that it’s probably a good idea to limit entries to only letters and numbers (see later)

Simple example.

Maybe you want users to enter a number (maybe a product or quantity a special code). You need to ensure all characters are just numbers, with no other stuff.

So, you create your custom field without any validation and put a note to the client to only enter numbers. How difficult could that be?

They enter: 12O.

But then later, you want to use that figure and add 1 to it (to make it 121) and its not working.

You wonder what could be wrong?

 

What is wrong is that the O is in fact an O, not a zero. And that breaks any calculations.

 

Its a lot easier to use a simple Regular Expression Validation String (usually shortened to RegEx) to check what is entered and warn the client if it’s wrong.

 

In the above example we want them to only enter numerals.

 

Here is what you would put in the Regular Expression Validation String box to only allow numerals:

 

^[0-9]*$

 

Here is another example which requires at least one numeral, but no more than three:

 

[0-9]{1,3}

 

Finally, as I mentioned earlier, you probably want to at least ensure the custom fields only contain alpha or numeric characters.

Here a RegEx expression to do that.

 

^[A-Za-z0-9]

 

This one allows you spaces as well.

 

^[a-zA-Z0-9 ]*$

 

Trevor

This is extremely helpful!  How would I go about making sure that the field meets these needs:

At least 8 characters long

No Spaces

No special characters other than @ or . 

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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