-1

Can I validate a user from entering zalgo texts to a form or any other place which prompts a data save, as explained in [Zalgo Texts]: How does Zalgo text work?

  • 1
    Possible duplicate of [Only allow certain characters to be entered in html textinput](https://stackoverflow.com/questions/16434174/only-allow-certain-characters-to-be-entered-in-html-textinput) – molnarm Jan 18 '18 at 10:08
  • I went through that question. But the answer is not complete for me and allows several characters in –  Jan 18 '18 at 10:14
  • Give precise examples of what you want to prevent and where you want to prevent it. Do you just want to only allow ASCII characters? – DJDaveMark Jan 18 '18 at 10:34

1 Answers1

1

As per your need you can use the following to validate a string as such. Furthermore you can use strip-combining-marks if you want to remove Unicode combining marks from strings.

function validateZalgo(s) {
    return /[^\u+0300-\u+036F]/.test(s);
}

var isValidated = validateZalgo('asd̨͈̺̱̤͚̤͚̤͚͈̆̆̆̆̆̆̆̆̆̆');

alert(isValidated);
Haswin
  • 697
  • 8
  • 20
  • 1
    But wouldn't that disallow characters like "€", "α", "", which are all clearly not Zalgo text? – lenz Jan 18 '18 at 10:17
  • @lenz true. It would, let me fix my answer. – Haswin Jan 18 '18 at 10:20
  • I wouldn't say it disallows "a few characters". From the 130k assigned codepoints in Unicode, it allows 256. Your approach disallows more than 99.8% of all possible characters. – lenz Jan 18 '18 at 13:59
  • 1
    Also, your approach allows "á", but not "ć". Would you say the second one is Zalgo, and the first one isn't? I'm curious why you chose exactly this range. – lenz Jan 18 '18 at 14:05
  • @lenz I think it's proper if the range is changed and updated as return /[^\u+0300-\u+036F]/.test(s); Range taken from http://en.wikipedia.org/wiki/Combining_character – Haswin Jan 18 '18 at 18:15
  • 2
    Now that's definitely more related to Zalgo text! There are a couple more combining characters if you scroll down on WP, and I personally would only call it Zalgo if they are used excessively, but let's leave all that as an exercise to the OP. It's not clear what they meant by "Zalgo" anyway. – lenz Jan 18 '18 at 21:00