Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Php - Limiting The Acceptable Characters In A Form Submission

Featured Replies

hey :)

 

i'm trying to work out how to limit the characters that can be accepted in a form but all i can find is how to check if a character exists in a string and i dont really want to make a list of every posible character to check against.

 

is there some way so that if doesn't only contain the acceptable characters it will return false?

 

e.g one of the fields is for color , i want it to check that all the characters are legal hex color code characters (a-f, 0-9) and return false if there is a character not in that range

 

thanks

you are talking about regular expressions even if you don't know it ;)

 

A regular expression (checked with ereg() or preg_match()) looks something like this:

 

/^([A-Za-z ]*)/

 

That means any character in:

- A to Z

- a to z

- [space]

repeated any number of times (* means 0 to infinity)

 

Regex's are a bitch to learn, but are very useful. Do a google, and prepare for your brain to melt ;)

 

An example for a hex code is:

/^([#]{0,1})([0-9A-Fa-f]{6}|[0-9][A-Fa-f]{3})/

 

The caret (^) means "from the beginning), so breaking the actual regex down,

([#]{0,1}) = a hash, either not there or only 1 of

[0-9][A-Fa-f] = any of 0123456789AaBbCcDdEeFf

{6} = exactly 6 of the characters within the preceding range

| = or

 

so

 

"from the beginning, a hash (or no hash) followed by either 3 or 6 of any of the following 0123456789AaBbCcDdEeFf"

  • Author

thank you , thats exactly what i was looking for ^^

 

i knew there had to be a function somewhere for it but i just couldn't find it ><

 

/me prepares to melt what little is left of her brain :p

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.