How to validate custom fields in moodle

1.4k views Asked by At

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

1

There are 1 answers

0
Russell England On BEST ANSWER

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