Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET2.0
in c#.net,for a textbox,it should accept all numbers,alphabets,special characters but when i give numbers alone it should throw error as"enter alphabets also"...how to code...can anyone help me.please..
Posted 28-Dec-12 5:49am
Edited 28-Dec-12 5:50am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Option 1: Use C# Regex class[^]. The codition to check: at least one non-digit character. So, the acceptance pattern could be @"\D". E.g.
bool IsOk(s) { return Regex.IsMatch(s, @"\D"); }
 
Option 2: loop over all characters of the string an check with char.IsDigit[^] method if at least one character is not a digit, e.g.
bool IsOk(string s) { return s.Length > 0 && s.Any(c=>!char.IsDigit(c));
 
Cheers
Andi
  Permalink  
v2
Comments
nityasri at 28-Dec-12 12:08pm
   
@andreas thanks
Andreas Gieriet at 28-Dec-12 14:48pm
   
You are welcome.
Andi
PS: Please mark if any of the solutions solve your problem.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
nityasri at 28-Dec-12 11:53am
   
@krunal..thanks
Krunal Rohit at 28-Dec-12 11:54am
   

If you're satisfied with the given answer, Accept the Solution :)
-Krunal R.

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

  Print Answers RSS
0 Maciej Los 404
1 OriginalGriff 379
2 CPallini 145
3 Sergey Alexandrovich Kryukov 142
4 Hard_Rockz 115
0 OriginalGriff 5,634
1 Sergey Alexandrovich Kryukov 4,763
2 Peter Leow 2,954
3 Maciej Los 2,614
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web04 | 2.8.140718.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid