Best way to validate for HTML special chacacters?
I am working on a project and I need to check for HTML special characters for text input boxes.
What is the best way to go about that? There doesn't seem to be a function to call like PHP has. I thought about using a RegEx. Would there be a better way?
I have no code to post as I am just trying to get ideas.
If you just want ideas, then other than RegEx, you could first trim the string, then use str_split and compare each character using indexOf to see whether it's a letter (upper case or lower case), number or space. If it's neither, then chances are it's a special character. Alternatively, you could do the opposite in which you use str_split and indexOf but your comparison string looks only for special characters. Either way, I wouldn't try to do a real-time validation, in which it would check the keyCodes since you have to account for the fact a user may use a backspace key, number pad, other random keys, etc... .
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)