can textbox accept special characters like "( ,)'-" along alpha

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got a function that can accept just Alphabet characters but is it a way
to get it to accept special characters like "(" or ")" or "-" or just ablank
space " " here is the code that I'm using that is prove to work on accepting
just alphabet in the text box


'**********************************
'Declarations section of the module
'**********************************
Option Compare Database
Option Explicit
'===============================================================
' The following function is named IsAlpha(). It accepts a string
' argument and returns either True (-1) or False (0).
'===============================================================
Function IsAlpha(MyString) As Boolean
Dim LoopVar As Integer
Dim SingleChar As String

If IsNull(MyString) Then
IsAlpha = False
Exit Function
End If

For LoopVar = 1 To Len(MyString)
SingleChar = Mid$(MyString, LoopVar, 1)
If SingleChar < "A" Or SingleChar > "Z" Then
IsAlpha = False
Exit Function
End If
Next LoopVar

IsAlpha = True

End Function
Can anyone help please?
 
Hi Stan,

I'd do this by downloading the rgxValidate function from
http://www.mvps.org/access. This is a general purpose function for
validating a string against a pattern. For instance, this

rgxValidate(MyString, "^[A-Z]*$")

does the same job as your IsAlpha(), and you can just add other
characters to the pattern as required, e.g.

"^[-A-Z]*$" for "-" plus uppercase letters (note that the -
must be the first item in the square brackets;
anywhere else it's assumed to indicate a range
of characters, as in A-Z).

"^[- ()A-Z]*$") to allow spaces and parentheses too.
 
Hi John, I have q uick question This function has some optional pices
include in this code. Do I need to take them out if I'm not going to use and
also with the constant declaration do I need to add them fo the function
itself? And Thank you very much.
I am going to get credit to "John Nurick" in my final report.
John Nurick said:
Hi Stan,

I'd do this by downloading the rgxValidate function from
http://www.mvps.org/access. This is a general purpose function for
validating a string against a pattern. For instance, this

rgxValidate(MyString, "^[A-Z]*$")

does the same job as your IsAlpha(), and you can just add other
characters to the pattern as required, e.g.

"^[-A-Z]*$" for "-" plus uppercase letters (note that the -
must be the first item in the square brackets;
anywhere else it's assumed to indicate a range
of characters, as in A-Z).

"^[- ()A-Z]*$") to allow spaces and parentheses too.



I've got a function that can accept just Alphabet characters but is it a way
to get it to accept special characters like "(" or ")" or "-" or just ablank
space " " here is the code that I'm using that is prove to work on accepting
just alphabet in the text box


'**********************************
'Declarations section of the module
'**********************************
Option Compare Database
Option Explicit
'===============================================================
' The following function is named IsAlpha(). It accepts a string
' argument and returns either True (-1) or False (0).
'===============================================================
Function IsAlpha(MyString) As Boolean
Dim LoopVar As Integer
Dim SingleChar As String

If IsNull(MyString) Then
IsAlpha = False
Exit Function
End If

For LoopVar = 1 To Len(MyString)
SingleChar = Mid$(MyString, LoopVar, 1)
If SingleChar < "A" Or SingleChar > "Z" Then
IsAlpha = False
Exit Function
End If
Next LoopVar

IsAlpha = True

End Function
Can anyone help please?
 
I've got a function that can accept just Alphabet characters but is it a
way
to get it to accept special characters like "(" or ")" or "-" or just
ablank
space " "

You can do it in one line like this, and define whatever you like in the
target string:

IsAlpha = 0 < Instr( _
"abcdefghijklmnopqrstuvwxyz" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
"()- ", _
Left$(strMyString, 1))

The call to Left$() insures you against passing a multi-char string,
although of course it will fail if passed an empty string.

Hope that helps


Tim F
 
Hi Stan,

You need to paste everything between ********CODE START********* and
*********CODE ENDS********** into a standard code module in your
database. The "Optional" lines relate to optional arguments of the
rgxValidate function; they're not bits of code that can be omitted.

There's no need to include the separate block of Public Const
declarations. If you want to make use of one or more of them, just paste
it/them at the top of the code module, between
Option Explicit
and
Public Function rgxValidate(...



Hi John, I have q uick question This function has some optional pices
include in this code. Do I need to take them out if I'm not going to use and
also with the constant declaration do I need to add them fo the function
itself? And Thank you very much.
I am going to get credit to "John Nurick" in my final report.
John Nurick said:
Hi Stan,

I'd do this by downloading the rgxValidate function from
http://www.mvps.org/access. This is a general purpose function for
validating a string against a pattern. For instance, this

rgxValidate(MyString, "^[A-Z]*$")

does the same job as your IsAlpha(), and you can just add other
characters to the pattern as required, e.g.

"^[-A-Z]*$" for "-" plus uppercase letters (note that the -
must be the first item in the square brackets;
anywhere else it's assumed to indicate a range
of characters, as in A-Z).

"^[- ()A-Z]*$") to allow spaces and parentheses too.



I've got a function that can accept just Alphabet characters but is it a way
to get it to accept special characters like "(" or ")" or "-" or just ablank
space " " here is the code that I'm using that is prove to work on accepting
just alphabet in the text box


'**********************************
'Declarations section of the module
'**********************************
Option Compare Database
Option Explicit
'===============================================================
' The following function is named IsAlpha(). It accepts a string
' argument and returns either True (-1) or False (0).
'===============================================================
Function IsAlpha(MyString) As Boolean
Dim LoopVar As Integer
Dim SingleChar As String

If IsNull(MyString) Then
IsAlpha = False
Exit Function
End If

For LoopVar = 1 To Len(MyString)
SingleChar = Mid$(MyString, LoopVar, 1)
If SingleChar < "A" Or SingleChar > "Z" Then
IsAlpha = False
Exit Function
End If
Next LoopVar

IsAlpha = True

End Function
Can anyone help please?
 
Thank you for your help in this matter I' m very thankful for the web site
information it realy helped me out of a sticky wicked.
Cheers

John Nurick said:
Hi Stan,

You need to paste everything between ********CODE START********* and
*********CODE ENDS********** into a standard code module in your
database. The "Optional" lines relate to optional arguments of the
rgxValidate function; they're not bits of code that can be omitted.

There's no need to include the separate block of Public Const
declarations. If you want to make use of one or more of them, just paste
it/them at the top of the code module, between
Option Explicit
and
Public Function rgxValidate(...



Hi John, I have q uick question This function has some optional pices
include in this code. Do I need to take them out if I'm not going to use and
also with the constant declaration do I need to add them fo the function
itself? And Thank you very much.
I am going to get credit to "John Nurick" in my final report.
John Nurick said:
Hi Stan,

I'd do this by downloading the rgxValidate function from
http://www.mvps.org/access. This is a general purpose function for
validating a string against a pattern. For instance, this

rgxValidate(MyString, "^[A-Z]*$")

does the same job as your IsAlpha(), and you can just add other
characters to the pattern as required, e.g.

"^[-A-Z]*$" for "-" plus uppercase letters (note that the -
must be the first item in the square brackets;
anywhere else it's assumed to indicate a range
of characters, as in A-Z).

"^[- ()A-Z]*$") to allow spaces and parentheses too.



I've got a function that can accept just Alphabet characters but is it a way
to get it to accept special characters like "(" or ")" or "-" or just ablank
space " " here is the code that I'm using that is prove to work on accepting
just alphabet in the text box


'**********************************
'Declarations section of the module
'**********************************
Option Compare Database
Option Explicit
'===============================================================
' The following function is named IsAlpha(). It accepts a string
' argument and returns either True (-1) or False (0).
'===============================================================
Function IsAlpha(MyString) As Boolean
Dim LoopVar As Integer
Dim SingleChar As String

If IsNull(MyString) Then
IsAlpha = False
Exit Function
End If

For LoopVar = 1 To Len(MyString)
SingleChar = Mid$(MyString, LoopVar, 1)
If SingleChar < "A" Or SingleChar > "Z" Then
IsAlpha = False
Exit Function
End If
Next LoopVar

IsAlpha = True

End Function
Can anyone help please?
 
Thanks Tim for the help.
Cheers

Tim Ferguson said:
You can do it in one line like this, and define whatever you like in the
target string:

IsAlpha = 0 < Instr( _
"abcdefghijklmnopqrstuvwxyz" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
"()- ", _
Left$(strMyString, 1))

The call to Left$() insures you against passing a multi-char string,
although of course it will fail if passed an empty string.

Hope that helps


Tim F
 
Back
Top