Hi
Is there an easy way to check if a string contains only alphanumeric and 'dot' characters? For example, a valid string might contain "12.1.6z", "1.2.3", "3.3.9cc", etc. No other characters are allowed.
Thanks.
Robie
make sure string only contains alphanumeric & DOT
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
-
- Administrator
- Posts: 78920
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: make sure string only contains alphanumeric & DOT
Do you want to allow letters with accents such as é or ü ?
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: make sure string only contains alphanumeric & DOT
Thanks for quick response Hans.HansV wrote:Do you want to allow letters with accents such as é or ü ?
The answer is no - standard alphabet is fine.
-
- Administrator
- Posts: 78920
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: make sure string only contains alphanumeric & DOT
You can use this function:
Example of use:
Code: Select all
Function TestString(s As String) As Boolean
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.Pattern = "^[A-Za-z0-9.]+$"
TestString = re.Test(s)
End Function
Code: Select all
Dim MyString As String
MyString = "Ro.b.ie.37"
If TestString(MyString) Then
' MyString meets the condition
Else
' MyString does not meet the condition
End If
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: make sure string only contains alphanumeric & DOT
Thank you so much Hans, will try it out soon.HansV wrote:You can use this function:
Example of use:Code: Select all
Function TestString(s As String) As Boolean Dim re As Object Set re = CreateObject("VBScript.RegExp") re.Pattern = "^[A-Za-z0-9.]+$" TestString = re.Test(s) End Function
Code: Select all
Dim MyString As String MyString = "Ro.b.ie.37" If TestString(MyString) Then ' MyString meets the condition Else ' MyString does not meet the condition End If
![Clapping :clapping:](./images/smilies/clapping.gif)