0

I am trying to match a name with the following regex

/^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð ,\'\-]+$/

This matches the following examples:

  • Tom Dooley
  • D'Agaene-Venus
  • Tom

However, when my application starts I don't want my validator to match the /''/ string in my text input, but I would want to match the /'/ in the body of the name like in D'Agaene above.

How best to achieve this. I have tried many options without success. I suspect some negation should be include bu just have not gotten it.

st_clair_clarke
  • 5,453
  • 13
  • 49
  • 75
  • Do you really mean to include `.` in the regex? Or should that be `\.`? – sideroxylon Feb 03 '16 at 01:53
  • On second thought a dot is never included in a name. You can leave it out - corrected the request. Thanks – st_clair_clarke Feb 03 '16 at 01:56
  • OK - try running your regex again without the dot. As it was not escaped, it was matching more than you might have wanted (not just a period). – sideroxylon Feb 03 '16 at 01:57
  • Tried it. It did not make any difference to the validation. – st_clair_clarke Feb 03 '16 at 02:03
  • Please post a sample string that you want to validate. – sideroxylon Feb 03 '16 at 02:03
  • 1
    Harry S. Truman had a dot in his name (the "S." was just an initial which stood for nothing). – m69's been on strike for years Feb 03 '16 at 02:05
  • @sideroxylon Please see the list above. – st_clair_clarke Feb 03 '16 at 02:09
  • @m69 Point taken. Some may use the dot with a middle initial or a title like Prof. – st_clair_clarke Feb 03 '16 at 02:11
  • So, if there is a '' anywhere in the string, you just want the match to fail, or you want that to be removed? While your ask is for the regex, maybe you can consider running through a string search for '' first, and then decide whether you want to use the regex or not. Just a thought. – sal Feb 03 '16 at 02:16
  • @sal If '' is present as the only content of the input box, as is my current issue, I would like the regex to give a match as a valid entry. '' should not be present anywhere in the string either, but ' is a valid character as shown in the second list item above. – st_clair_clarke Feb 03 '16 at 02:23
  • @sideroxylon: The original regex was fine. When it's in a character class, `.` matches a literal `.`. (None of those other characters needed escaping either. The `-` was correctly placed at the end of the list, and `'` never has any special meaning in regexes.) – Alan Moore Feb 03 '16 at 02:53
  • @Alan Moore: Thanks Alan. I was reading about it after the initial comment and found it to be correct. No harm done though. I could put it back after I have some proposed solution. Any thoughts on the solution? – st_clair_clarke Feb 03 '16 at 03:12
  • @st_clair_clarke: I'm still not sure what you're asking. Are you saying it's okay to have quotation marks (`"`) in the name? Or double apostrophes (`''`)? If so, *where* are they allowed? – Alan Moore Feb 03 '16 at 03:21
  • @Allan More: No Allan. Initialization of the application places an empty string in the input field. Once I use `required` in the html markup the empty string is place there and the validator flag the input box as invalid - marks it in red. I would like to remove this red mark at initialization - I thought regex would be able to help. No '' or "" CAN BE PRESENT IN THE REGEX - they are illegal. However, ' is a legal character in some names, as, for example, D'Agaene. Hopes this helps. – st_clair_clarke Feb 03 '16 at 03:26
  • If the field is required, then an empty string *is* invalid. But you can change the styling to better communicate that the input isn't wrong, just missing. See [here](http://www.the-art-of-web.com/html/html5-form-validation/) for more info. – Alan Moore Feb 03 '16 at 04:12
  • Check http://stackoverflow.com/questions/155739/detecting-unsaved-changes – Wiktor Stribiżew Feb 03 '16 at 23:30
  • Your information is conflicting. Once you say _'' is present as the only content of the input box_, then you say _the application places an empty string in the input field._ `''` is not an empty string, it is a string of two apostrophes. So, what do you really have? – Armali Apr 05 '16 at 08:46
  • Did you finally use [this](https://regex101.com/r/Ivu4EY/1)? – Wiktor Stribiżew May 05 '18 at 09:05
  • Yes. I did. Cheers – st_clair_clarke May 06 '18 at 11:27

0 Answers0