Results 1 to 2 of 2

Thread: Best way to validate for HTML special chacacters?

  1. #1
    Join Date
    Nov 2013

    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.

  2. #2
    Join Date
    Feb 2014
    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... .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center