Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a String which Contains mix of language for ex:

1)Hello, Bing Hope you doing well & for Your info 10-09-2015 planned for Get-together.

in this Case it should return me true as it don't contain any other character other than Alphanumeric with some special character like ,&.

2)Hello, Bing आशा you doing well & for Your info 10-09-2015 की योजना बनाई for Get-together.

But in this Case it should return me false as it contain Hindi Characters other than Alphanumeric with some special character like -,&.

How to Validate this in Asp.net code behind.
Posted
Comments
CHill60 20-Aug-15 10:50am    
What have you tried?

One way would be to check if your string contains characters outside the range of extended ANSI characters.

Using Linq
C#
var s = "Hello, Bing आशा you doing well & for Your info 10-09-2015 की योजना बनाई for Get-together.";
Console.WriteLine(s.Any(c => c > 255));

which is the equivalent of
C#
var s = "Hello, Bing आशा you doing well & for Your info 10-09-2015 की योजना बनाई for Get-together.";
var any = false;
foreach (var c in s)
{
    if (c <= 255) continue;
    any = true;
    break;
}
Console.WriteLine(any);


(You might like to replace that 255 with a constant)
 
Share this answer
 
v2
Comments
Member 11335401 20-Aug-15 23:29pm    
It Worked Fine for my Case..I never thought this will be so simple, i was trying with Regex Validation and so on for this..Thanks dude.
CHill60 26-Aug-15 8:21am    
No problem. I find that Regex can quite quickly become unwieldy.
Note that ppolymorphe has a good point in Solution 2 - you can amend the linq statement to avoid ranges within the character range something like this: var any = s.Any(c => c > 255 || (c <= 165 && c >= 198)); (note the numbers aren't correct - check which ones you would need on-line e.g. http://www.theasciicode.com.ar/[^])
Member 11335401 26-Aug-15 23:42pm    
I am just checking whether my string contains letters from regular keyboard characters..So your both solution works perfectly in my case..

Solution: You have to write your own function that will check your string.
-You have to define the list of chars that are acceptable for you.
-then the function have to check every char in your string against your acceptable set of chars.

Depending on which country you are, Alpha-numeric chars are not the same set.
Problems
- In France, éèàçêüù are acceptable as Alpha chars
- some chars with ascii value under 128 are not alpha-numeric
=+-*/_(){}&|"'<>°@\#,?;.:!%
 
Share this answer
 

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