How to validate custom fields in moodle

is there a way to add regex validation in custom fields for signing up in moodle? I'm tricking with the signup_form.php and signup.php files but i can't manage to achieve it. I added some fields with the addelement() function and addrule() but it would be a problem in upgrading. How can i validate fields via lib.php?

Really thanks for your answer

Upvotes: 3

Views: 1518

Answers (1)

Russell England
Russell England

Reputation: 10241

Maybe something like this after profile_signup_fields($mform); in signup_form.php

$form->addRule('profile_field_shortname',
    get_string('regexerrormessage', 'pluginname'), 'regex', 'regexexpression');

There is a list of rules over here:

https://pear.php.net/manual/en/package.html.html-quickform.intro-validation.php

Upvotes: 1

Related Questions