Replace special characters like Ôûîâ

397 views Asked by At

I came up with a really strange problem with today. I am creating an application with Laravel under Firebird database so it is very important to not insert illegal strings or chars into the query. Yesterday I got an error report about this kind of exception so I checked the code what could be the problem. Right now I created a validation rule with the following regular expression:

regex:/[a-zA-Z0-9\.\-\,üÜóÓöőŐúÚűŰáÁiÍûé]+/

It works great actually but I noticed that in case of the user inserts charachters like these:

Ôûîâ

It will throw the exception above. For the texteditor I am using TextAnguar, is there any way to prevent these kind of input to be saved or replaced with standard characters? (Like üöőú, Hungarian letters)

Thank you for your answers!

Best wishes, Gábor Magyar

1

There are 1 answers

1
Wiktor Stribiżew On BEST ANSWER

You may add these chars to the character class

regex:/[-a-zA-Z0-9.,üÜóÓöőŐúÚűŰáÁiÍûéÔûîâ]+/
                                     ^^^^

Note that the - at the start (or end) of the character class does not have to be escaped to denote a literal hyphen. A , and . don't have to be escaped inside a character class.