We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35756
    • 166 Posts
    Hi there!

    I'm trying to get regexp working within the Update-Profile-call:

    [[!UpdateProfile? 
    &preHooks=`imageUpload`
    &validate=`
    vorname:required,
    nachname:required,
    start:required,
    thema:required,
    abstract:required,
    jobemail:email,
    jobphone:regexp=^/[0-9 \s\/-]{8}/^,
    email:email:required:checkEmail
    `]]


    I want to check if the value in the field "jobphone" does contain only numerals PLUS the "signs/characters" - (hyphen), / (slash) and space.

    This works for the first 8 characters that are saved as the value...how can I get this to be working for the whole value, as I don't know how many characters will be enterred by the users? I tried it like this

    {0, }


    but this doesn't seem to work.

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      How about this (assuming that the phone no. is the only thing on the line)?


      jobphone:regexp=^/[0-9 \s\/-]+\s*$/^


      You might also want to allow phone numbers with parentheses, periods, and plus signs:

      jobphone:regexp=^/[0-9\(\)\+\. \s\/-]+\s*$/^


      The problem with the regexes above is that they will allow clearly BS phone numbers like:

      000-000-0000.

      Here's a more stringent one that also allows the user to add an extension:

      /^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$/i

      [ed. note: BobRay last edited this post 9 years, 7 months ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 35756
        • 166 Posts
        Hello Bob!

        And thanks again for getting involved and helping!

        But by using any of your solutions you posted the validation never succeeds. I'm alaways getting an error message.

        I "prefill" the jobphone-input-text-field with "040-123456" to give the users a suggestion how to fill the field; but as there might be foreign users too I have to add the "+" and brackets "(" ")" I think...

        That would be like this I think:

        jobphone:regexp=^/[0-9 \+\(\)\s\/-]{8}/^,


        But I've got still the problem this only validates the first 8 entered characters.

        By changing this part:

        {8}/^,


        to your suggestion:

        +\s$/^,


        the same error as before happens, the validation never succeeds although I only used numerals.
        • discuss.answer
          • 3749
          • 24,544 Posts
          Sorry, the end of my examples should be modified to allow 0 or more \s characters:

          +\s*$/^,


          There's an excellent online regex tester here: http://regex101.com/
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 35756
            • 166 Posts
            Hello Bob!

            Thank you again for posting the correct solution, this is working like a charm! By getting this to work I can handle some other validations too now, that's great!

            And the link you posted looks helpful, thanks for that too!
              • 3749
              • 24,544 Posts
              I'm glad I could help.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting