Click here to Skip to main content
15,923,164 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a field userId where i want validation check for special charaters. i want to restrict user to input any special character.

if user input any special character then a message display.
How can i do it. Please help
Posted
Comments
Sergey Alexandrovich Kryukov 27-May-11 13:30pm    
It depends also on how data is entered (see suggestions you got). This is not clear from your question. What is it? Overall, you got good solutions, just use the advices.
--SA

You can use Regular expression validator or filtered textbox extender in ajax toolkit....
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-May-11 13:29pm    
True, a 5. What exactly to use depends on complexity of the validation rules. Validation step may or may not be needed.
--SA
I would suggest you to use a Regular Expression Validator control.

See:
http://msdn.microsoft.com/en-us/library/ff650303.aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-May-11 13:27pm    
It would work, my 5, but, depending on control, filtering out of characters when a text is edited should also be considered, in replacement or in addition to validation. It depends on complexity of the rules.
--SA
instead of restricting special characters...u can allow to enter only numbers or characters..that would be easy.

see this link for more info

http://www.tizag.com/javascriptT/javascriptform.php[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-May-11 13:28pm    
That is a good suggestion, my 5. However, it may or may not be used with validation. It depends on complexity of the rules. My 5.
--SA
You can use this

string strRet
string s = "9!@$%^^quali52ty3"; //This where you can put your characters
foreach(char c in s)
{   
  if (char(13) = c || char('@') // write all the special character you want to show
   {
     strRet =strRet + c;
   }
} 
   lblmessage.text = "This is a special Character. " + strRet
 
Share this answer
 
v3
Comments
rahul dev123 27-May-11 3:50am    
if (char(13) = c || char('@') )
this line show error invalid char
cuteband 27-May-11 4:26am    
yeah because you have to fix this line
if (char(13) = c || char('@') = c )
Sergey Alexandrovich Kryukov 27-May-11 12:58pm    
Fix your own code first! What you right won't even compile. Please check what you post before posting. For now, my vote is 1.
--SA

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