Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Javascript Form Validation


Go to End


381 Views

Avatar
Bagzli

Community Member, 71 Posts

20 February 2015 at 1:28pm

Edited: 20/02/2015 1:41pm

Hello,

I'm trying to set some javascript form validation but I can't seem to figure it out. Any help is most appreciated.

Here is what I tried but it doesn't produce any error messages: (I'm mainly interested in getting a regex validator working, the required field validator is already set)

$fields = new FieldList (
            TextField::create('MyText').setAttribute('data-validation-regex', '[0-9]+'),
...

When I try to use '->' instead of '.' I get the following error:

PHP Parse error:  syntax error, unexpected '->' (T_OBJECT_OPERATOR)