phpformsmoodlequickform

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


Solution

  • 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