isAlpha
for ASP
For those C programmers out there, you know what I'm talking about! For those who don't, there
is a standard C function called isAlpha
that is used to verify that a string has only
alphabetic characters (A-Z, a-z). There are times when you need to verify that a user has entered
only alpha characters into a string. For example, if you are asking for a unique username, you might
want to limit the entry to only alpha characters (i.e. no numbers, no special characters, no spaces.)
Well, this isn't too difficult to do using ASP. We just need to create a function that takes as its input a string, and returns true if the string contains just alpha characters, and false otherwise. So let's look at some code!
|
This function loops through the input string one character at a time. If the current character it's examining isn't A-Z, it returns false. If we loop through the entire string and all characters are between A to Z, then we return true.
We could make use of this function by a few simple lines of ASP code. Imagine that we have a form that
calls this ASP page when submitted. In that form, there was a field called UserName
, which
we want to verify has only alpha characters. Here's some ASP code we could use to ensure
UserName
was valid:
|
This simple example demonstrates how to use the isAlpha
function.
I hope you find this script useful! As always, if you have any comments, ideas, or criticisms, I encourage you to send me feedback!
Happy Programming!
Attachments:
isAlpha
in text format
Related Articles
Asc
functionMid
functionUCase
function