Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI,
I have a file.While renaming it using for windows key board ,it is not allowing special characters as i am using a regular expression,but while i renaming the file using Mac key board its allowing special characters. How could I avoid this issue?Is there any regular expression which ll check for special characters in both MAC and Windows key board?Please tell me.Regular exp that I used for validating Windows special charactes is
C#
<dxe:TextEditSettings MaskType="RegEx" Mask="[^<>/?:*\\|"]{1,100}" MaxLength="100" MaskBeepOnError="True" />


Thanks
Bikash
Posted
Comments
Sergey Alexandrovich Kryukov 30-Oct-15 3:21am    
"Special characters"? I never met one. :-)
Any physical keyboard allows to enter much more characters which you can even imagine. What you are trying to do is just bad misconception.
—SA
Sinisa Hajnal 30-Oct-15 3:30am    
Instead of trying to exclude all special characters, change the regex to only INCLUDE wanted characters.
Member 11246037 30-Oct-15 3:52am    
Ya ,I have done and only allow the characters that are we use to rename a file in our Windows os.But in apple key board its not supporting.its allowing a character like  for renaming.that's creating problem for me.
Philippe Mori 30-Oct-15 13:41pm    
In practice, if does not make sense to be that restrictive. In many language, they use different characters and it would not be very friendly if a user cannot use characters like âëūñÿsæ just to show a few.

In a case like this, it is usually preferable to go on the safe side and ensure that any valid file name can be used and possibly miss a few bad one on some file systems.
Richard MacCutchan 30-Oct-15 5:54am    
This has nothing to do with keyboards. It is just that your regex only checks for a specific subset of characters. As suggested, you need a match for only those characters that are allowed.

1 solution

Here is regex that matches alphanumerics and underscore
"^[a-zA-Z0-9_]*$"

caret matches start of the string
thing between [] matches letters and numbers and underscore
* says 0 or more
$ matches end of the string

You can add any other character you want (but some need escaping (dots, parentheses, slashes and similar).

You could try "^\w*$" where \w represents a word, but it is dependant on your regex engine implementation.

Good luck.
 
Share this answer
 
v3
Comments
phil.o 30-Oct-15 7:16am    
5'd
Philippe Mori 30-Oct-15 13:43pm    
I would not recommand being such restrictive. It would really be not friendly if a user cannot write characters like æëñč if he need them in is language.
Sinisa Hajnal 30-Oct-15 17:01pm    
That is why I said he can add characters needed (depends on the culture, my own has čćšđž and doesn't have qwxy). And my own name is spelled wrong (it should be Siniša) on this site due to english alphabet and I don't find that specially restrictive.
He could use \w\d (words and digits).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900