We are currently working on the forum. For the short-term, all forum content will be in read-only format. We apologize for the interruption and look forward to collaborating with you shortly. All the best in your research!

validation and regexp sintax

dariopiazzadariopiazza Posts: 4
hi to all, 
I ask for help because I can not run the validation function in a field that must contain the initials of the patient in the format "nn" (name) and "ss" (surname). 
I use the syntax: regexp: /[A-z]{2}/ 
Unfortunately, however, if that field is filled in with numbers or letters with numbers greater than 3, I can not display the validation error message expected. 

can someone help me?
Post edited by bbaumann on


  • tdpurnattdpurnat Posts: 126
    via Email

    You mean that you only want to allow exactly two lower case letters? I
    think your mix of capital and lowercase letters is not making it work.

    I'm not a regex wiz, but this would be a crude way of doing it. If someone
    would write three letters for example, it would still match up the two

    regexp: /[a-z][a-z]/


    regexp: /[a-z]{2}/

    I find this tool below useful for testing my regular expressions:
  • tdpurnattdpurnat Posts: 126
    Sorry, I just realized that you were asking to use a regex to validate that the answer is exactly 2 characters long.

    I'd recommend that you use javascript for validating the length of a string field. see example here:

  • GerbenRienkGerbenRienk Posts: 838 ✭✭✭
    Hello Dario,
    Can you explain a bit more what it is you want and preferably give some examples of valid and non-valid entries?
    Both your own solution and Tina's suggestions look OK to me.
    Many thanks,

    Gerben Rienk
This discussion has been closed.