0

how can we match non-keyboards characters using php?? characters like-- ♠♣♥♦

i want to check if a data contains non-keyboard characters and if it does i'll have to reject it as per my requirements.

developer
  • 2,042
  • 10
  • 40
  • 59
  • 2
    Maybe you should change perspectives and only accept certain characters like `a-zA-Z0-9!@#$%^&*()` etc... – Russell Dias Feb 28 '11 at 12:50
  • 2
    are you looking to match a list of specific characters, or any non-keyboard character in general? – Spudley Feb 28 '11 at 12:51
  • 2
    What is the thinking behind this, what do you need this for? What about chinese and other alphabets? And eastern european users (who have `Š` on their keyboards) will thank you very much :) – Pekka Feb 28 '11 at 12:51
  • 1
    @Russell Dias: Because as we know, everybody speaks English. I'm not entirely sure what the OP is trying to do, but "only ASCII characters are valid" is a bit naïve (sic!) approach. – Piskvor left the building Feb 28 '11 at 13:06
  • yeah right i want to check if a data contains non-keyboard characters and if it does i'll have to reject it as per my requirements. – developer Mar 01 '11 at 05:08
  • @Spudley : I want to match any non-keyboard character not any specific one. – developer Mar 01 '11 at 05:40
  • 1
    @developer — any character that is not on *your* keyboard, not on the *visitors* keyboard (which you can't know), not on *any* keyboard or not on *all* keyboards? – Quentin Mar 01 '11 at 06:06
  • Hang on, is that an ampersand in that list? What keyboards don't have ampersand characters fairly prominently on them? And can I never have to program on one of them?! – Quentin Mar 01 '11 at 06:09
  • @David Dorward : - above list is just an example of what i need. The data can contain any keyboard characters PLUS the non-keyboard ones. I just need to check if there's ANY non-keyboard character in my string then i have to reject it. Thats what i want.I hope its clear to you now. – developer Mar 01 '11 at 06:23
  • 1
    @developer — no, it isn't. What is a "keyboard character"? It isn't like there is one universal keyboard layout. – Quentin Mar 01 '11 at 08:52
  • Leeeet's see... */me mashes on his keyboard*: `áščjlkwqAER97é=+ěščáíuihPOeú)` I typed all that on my keyboard (each character with a single keypress, and no, the diacritical marks generally can't be dropped without loss of meaning). Do all those qualify as keyboard characters? (Mind you, I've seen much more exotic layouts, this one is at least mostly ASCII; and even various US keyboard layouts have different keys from each other) – Piskvor left the building Mar 01 '11 at 09:19
  • @all : i basically want just English characters..im not bothered about other languages here...its just those symbols(♠♣♥♦) that we dont usually find on normal keyboards.....i wanted to match them.....anyways my work is done...i took Russell Dias's advice of changing my perspective and so my program accepted only those characters that we want and have neglected all the others. – developer Mar 01 '11 at 11:13

1 Answers1

1

Try

Example:

var_dump( mb_ereg('⊃', "≥⊂⊃⊄⊆⊇⊕⊗") ); // 1

You might want to clarify the question to get better answers/examples.

Also see

Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559
  • 1
    Last living member of the `ereg` family? – Russell Dias Feb 28 '11 at 13:09
  • 1
    @Russel afaik none of the `mb_ereg*` functions are deprecated yet. Of course, the OP can also enable unicode for the `preg_*` family of functions as explained in that linked question. – Gordon Feb 28 '11 at 13:17