What are exampes of a "Regular expression" for Options. V 2.07?

One new feature in v 2.0.7 just released is:

“The ability to validate option (input and textarea) value by regular expression was added”.



Can someone give me a few examples of the type of regular expressions that can be used.

Is there one for setting a maxlenghth, max row specification?

I did find this expression:



^[\a-z\A-Z]{1,14}$



This validates the text field from 1-14 characters. Seemed to work in demo for a text field.

I can’t figure out how to include all numbers and all characters.

I allow any combination, including %, #, ! and other symbols.

Does any one know how to allow all standard characters? Or a good source of information for RegExp’s?

Thanks,

Bob

Same here! I am excited with the new feature. However, I am not sure how to use it.

Any one else tried RegExp yet? Any Examples?

http://www.regular-expressions.info

Hello! I was trying to allow any 3-digit letter as input field. I tried the following:

[QUOTE]^[a-z]|[A-Z]{3}$[/QUOTE] However, it does not allow input like Aaa or zZz … I can only get it to work as either [AAA] or [zzz]. How do I resolve it? I am a newbie. Thanks!

Grabbags:

Try this:

^[\a-z\A-Z]{3}$

Tried it on demo site and it worked.

I am looking for expressions for text boxes. Need to specify maxrows and maxlength validation.

I think I am ok with text areas. Have not even found one example that can be used for text areas

Bob

[quote name=‘pbannette’]Grabbags:

Try this:

^[\a-z\A-Z]{3}$

Tried it on demo site and it worked.

I am looking for expressions for text boxes. Need to specify maxrows and maxlength validation.

I think I am ok with text areas. Have not even found one example that can be used for text areas

Bob[/QUOTE]



Thank you, it works.

Hello,

Starting to get some usable expressions for CS-CART field in 2.0.7.

Having trouble chaining expressions.

Need some help:



This expression is good for a single line. It allows all alphanumeric characters and limits others to the ones in the expression (including spaces), maxlength 14.:



^([0-9a-zA-Z!@#$%^&*()-_=+ ]){0,14}$





This is the only one I could find for a text area.

This allows up to four rows and a maxlength for each row of 14.

^([^\r\n]{0,14}(\r?\n|$)){1,4}$



What I need help in is combining the two for text areas. I want to limit the characters that are permitted in the text area.



The sample of these fields are on the test site:

[url]http://treasurechestofgifts.com/test-category/test-product.html[/url]



Thanks,

Bob

That’s sad. No one follow up with you?

Only you, Grabbags!

I basically learned enough to do what I need.

Was hoping for more examples that can be used for CS-CART text field and boxes.

I don’t even understand the ones I am using, just change and test until it works.

Bob

[quote name=‘pbannette’]Only you, Grabbags!

I basically learned enough to do what I need.

Was hoping for more examples that can be used for CS-CART text field and boxes.

I don’t even understand the ones I am using, just change and test until it works.

Bob[/QUOTE]



Do you mind to teach me how to do 5-digit number or 1-digit of ‘0’?



any 5-digit number = ^[0-9]{5}$



Thanks in advance!

The reason that it is so difficult to write regular expressions is due to the javascript, core.js line 1580, which doesn’t handle metacharacters correctly (e.g. \n, \r, \b, \w, etc). All backslash metacharacters must have an additional backslash added.



So the expression:

^\t[\w]+$

needs to be entered as:

^\t[\w]+$



I have also submitted this problem to the bug tracker as:

[url]http://forum.cs-cart.com/vbugs.php?do=view&vbug_id=1933[/url]

I have just posted a solution to the RegExp problems in my Bug Report.



The details are as follows:

I have now done further testing of this problem with the following results.


  1. Amended line 1580 in core.js.

    From:

    var expr = new RegExp(regexp[id][‘regexp’]);

    To:

    var expr = new RegExp(regexp[id][‘regexp’],‘g’);


  2. To limit a “Text” option type to 25 characters I used the RegExp:

    ^[\w]{1,25}$


  3. To limit a “Textarea” option type to 15 words I used the RegExp:

    ^((\b[\w]+\b\s*){1,15})$



    Both tests now work correctly in my website, in particular the Textarea works correctly when the text has embedded linefeeds in it.



    I have also tested a variation on 3) above, to remove various punctuation characters so they are not counted as additional words:

    ^((\b[\w]+\b[\s\.,;:-_]*){1,15})$

Just a quick update.

This problem has been fixed in 2.0.15, see Bug Tracker:

[url]http://forum.cs-cart.com/vbugs.php?do=view&vbug_id=1933[/url]