473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How do you check a string against alphanumerics

Hi everyone,

In C# how do you verify if a string is alphanumeric?

Thanks for suggestions.
Nov 15 '05 #1
5 9118
Nader wrote:
Hi everyone,

In C# how do you verify if a string is alphanumeric?

Thanks for suggestions.

With Regular expressions.. \w+ should be enough to find out if a word is
alphanumeric. If you want the whole sentence.. you will need to write
a little expression. Look up help on Regular expressions to figure out
the complete thing.. Or somebody might help you out here ..

--
Girish Bharadwaj

Nov 15 '05 #2
Hi,

try
using System.Text.RegularExpressions.*;

bool bIsAlphaNum = Regex.IsMatch (strInput, "^\\w*$");

Replace * with + if you want empty strings to be considered not alpha
numeric.

^ matches begin of string,
\w* matches zero or more consecutive alphanumeric _characters_,
$ matches end of string.

HTH
greetings
"Nader" <na**********@hotmail.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Hi everyone,

In C# how do you verify if a string is alphanumeric?

Thanks for suggestions.

Nov 15 '05 #3
Thanks a lot for taking the time to reply. As \\w represents alphanumerics
and the underscore character I have to get rid of '_' also. Too bad there is
no built-in function.

"Jhon" <Jh**@a.a> wrote in message
news:PK*********************@phobos.telenet-ops.be...
Hi,

try
using System.Text.RegularExpressions.*;

bool bIsAlphaNum = Regex.IsMatch (strInput, "^\\w*$");

Replace * with + if you want empty strings to be considered not alpha
numeric.

^ matches begin of string,
\w* matches zero or more consecutive alphanumeric _characters_,
$ matches end of string.

HTH
greetings
"Nader" <na**********@hotmail.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Hi everyone,

In C# how do you verify if a string is alphanumeric?

Thanks for suggestions.


Nov 15 '05 #4
Hi,

try this expression instead:

bool bIsAlphaNum = Regex.IsMatch (strInput, "^[a-zA-Z0-9]*$");

HTH
greetings


"Nader" <na**********@hotmail.com> wrote in message
news:Ow**************@TK2MSFTNGP11.phx.gbl...
Thanks a lot for taking the time to reply. As \\w represents alphanumerics
and the underscore character I have to get rid of '_' also. Too bad there is no built-in function.

"Jhon" <Jh**@a.a> wrote in message
news:PK*********************@phobos.telenet-ops.be...
Hi,

try
using System.Text.RegularExpressions.*;

bool bIsAlphaNum = Regex.IsMatch (strInput, "^\\w*$");

Replace * with + if you want empty strings to be considered not alpha
numeric.

^ matches begin of string,
\w* matches zero or more consecutive alphanumeric _characters_,
$ matches end of string.

HTH
greetings
"Nader" <na**********@hotmail.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Hi everyone,

In C# how do you verify if a string is alphanumeric?

Thanks for suggestions.



Nov 15 '05 #5
Thanks Jhon, you motivated me to get back to Tom Archer's Inside C# to learn
regular expressions. I had skipped that part! :)
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: phil_nospam_schmidt | last post by:
I am scanning text that has identifiers with a constant prefix string followed by alphanumerics and underscores. I can't figure out, using pyparsing, how to match for this. The example expression...
6
by: Matt | last post by:
I want to check if the user enters alphabet or numbers only in the text box. If the user enters non-alphabet or non-numbers, I should pop up a message and doesn't allow the user to do that. I am...
16
by: Christopher Benson-Manica | last post by:
I'm wondering about the best way to do the following: I have a string delimited by semicolons. The items delimited may be in any of the following formats: 1) 14 alphanum characters 2) 5...
4
by: Hamed | last post by:
Hello How can I check if a string is empty? Thanks
3
by: Caspy | last post by:
I just get stuck on how to check if a user is a member of network (domain). I am building an internal tracking system with ASP.Net with Form authentication. When an user is added into the system,...
2
by: Robert Fitzpatrick | last post by:
I have a field in my pgsql 7.4.2 table that is char(6) type. This holds an ID that contains only numbers, but must be six characters in length. First two chars are the year followed by a sequential...
2
by: DesCF | last post by:
I have a textbox and a combobox on a toolstrip. The user enters either an ID in the textbox or selects a name from the combobox. When the user selects a name from the combobox the textbox is...
17
nitindel
by: nitindel | last post by:
Hi All, I have a text box and want to validate it like this: I want to enter Numerics or alphanumerics in the text box but not Alphabets alone.If Alphabets alone entered then...
1
by: MGM | last post by:
Hey everyone, I had a quick problem: I want to be able to send a string of data to a function and have it return that same string but only in alphanumerics. That is to say, if I sent it: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.