Click here to Skip to main content
Click here to Skip to main content

Validating Alphabets

, 19 Jun 2005
Rate this:
Please Sign up or sign in to vote.
The function to validate whether the input is in alphabets or not.

Introduction

The purpose of writing this article is to share my knowledge with others. In this article, I have written the code for checking the alphabets.

Purpose

Though this is very basic level code but sometimes we need to include this type of code, in our applications. We can use this code where the entries should be in alphabets like ‘First Name’, ‘Last Name’, etc.

Functionality

The variable is passed as “C_S” as a parameter to the function named “Check_Alphabets”. There are two variables in the function:

  • Var_Loop
  • Var_Len

Var_Loop is for the looping purpose whereas Var_Len contains the length of “C_S”. Next, the contents in the C_S are being converted to small case by using the LCase function. Next each character in the C_S is being checked in the “For Next” loop. If any character in C_S is not in the range of 97 – 122 ASCII characters then the function returns false. 97 is the ASCII of ‘a’ whereas 122 is the ASCII of ‘z’. If all the characters are in the range of 97 – 122 ASCII characters then the function returns true.

Source Code

Note: Please download source file for proper functioning of the code.

Sub Btn_Submit_OnClick(Sender As Object, E As EventArgs)
  Dim Var_Txt_Text As String
  Var_Txt_Text = Trim(Txt_Text.Text)
  If Var_Txt_Text = "" Then
   Lbl_Message.Text = "Please enter something in the text box."
   Exit Sub
  ElseIf Check_Alphabets(Var_Txt_Text) = True Then
   Lbl_Message.Text = "Congratulations! Input is in alphabets."
  Else
   Lbl_Message.Text = "Sorry! Input is not in alphabets."
  End If
 End Sub
 
 Function Check_Alphabets(C_S)
  Dim Var_Loop, Var_Len
  Var_Len = Len(C_S)
  C_S = LCase(C_S)
  For Var_Loop = 1 To Var_Len
   If Mid(C_S, Var_Loop, 1) < Chr(97) Or Mid(C_S, Var_Loop, 1) > Chr(122) Then
    Return False
   End If
  Next
  Return True
 End Function

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

naveedmazhar

Pakistan Pakistan
I am a computer science graduate. I have been working in ASP.Net since January 2003.

Comments and Discussions

 
GeneralAn idea.... Pinmemberje_gonzalez20-Jun-05 19:31 
GeneralRe: An idea.... PinmemberIssa Qandil30-Jun-05 4:35 
QuestionAre you serious? Pinmembermav.northwind20-Jun-05 0:29 
AnswerRe: Are you serious? Pinmemberkaangonel20-Jun-05 1:34 
GeneralRe: Are you serious? Pinmembermav.northwind20-Jun-05 2:03 
AnswerRe: Are you serious? Pinmemberilikc0de12-Jun-06 12:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141030.1 | Last Updated 20 Jun 2005
Article Copyright 2005 by naveedmazhar
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid