Morgoth
02-02-2003, 12:36 AM
I am going very slow at the moment, and I can not remember how to check a string to make sure it's only numbers and letters as characters and not other symbols.
Thank you.
Thank you.
|
||||
Check, Numbers and Letters Only.Morgoth 02-02-2003, 12:36 AM I am going very slow at the moment, and I can not remember how to check a string to make sure it's only numbers and letters as characters and not other symbols. Thank you. oracleguy 02-02-2003, 01:56 AM http://www.codingforums.com/showthread.php?s=&threadid=7472 Like this? Morgoth 02-02-2003, 02:01 AM I found it out... This will be my function... Dim Z As String, X As Integer For I = 1 To Len(Z) X = Asc(Mid(Z, I, 1)) If Not ((X >= 48 And X <= 57) Or (X >= 65 And X <= 90) Or (X >= 97 And X <= 122)) Then MsgBox "error" End If Next Morgoth 02-02-2003, 02:03 AM Originally posted by oracleguy http://www.codingforums.com/showthread.php?s=&threadid=7472 Like this? Well, I didn't see your post there until now, but thanks for the support! whammy 02-02-2003, 03:20 AM I have a more concise function now - perhaps may be improved upon in the future, but as simple as I know how - however I do like your approach of using Asc() values, Morgoth, that's yet another way to do it! It's probably not as fast though since you're looping. Function IsAlphaNumeric(str) Dim ianRegEx Set ianRegEx = New RegExp ianRegEx.Pattern = "[^a-zA-Z0-9]" ianRegEx.Global = True IsAlphaNumeric = (ianRegEx.Test(str) = False) End Function http://www.solidscripts.com/displayscript.asp?sid=10 Example usage: <% If IsAlphaNumeric("SDF(**(&") = False Then Response.Write("Please refrain from using characters other than letters or numbers in your entry.") End If %> :) Morgoth 02-02-2003, 05:31 AM Thank you whammy. I haven't really gotten into RegExp. I don't really understand exactly what it is. Do you hav any tutorials? I used two scripts, now three, that use this, and I want to understand what it is doing, how, and why. Thanks again. whammy 02-02-2003, 04:21 PM Some great tutorials here: http://www.siteexperts.com/tips/functions/ts23/page1.asp http://developer.netscape.com/docs/manuals/js/client/jsguide/regexp.htm http://www.webreference.com/js/column5/ http://www.devshed.com/Server_Side/Administration/RegExp/ What this does: Function IsAlphaNumeric(str) Dim ianRegEx Set ianRegEx = New RegExp ianRegEx.Pattern = "[^a-zA-Z0-9]" ianRegEx.Global = True IsAlphaNumeric = (ianRegEx.Test(str) = False) End Function [^a-zA-Z0-9] [] - character grouping brackets ^ - when inside grouping brackets, means "NOT" (otherwise it represents the beginning of the string) a-zA-Z0-9 - the characters NOT to match the reason I use IsAlphaNumeric = (ianRegEx.Test(str) = False) is because if you use: [a-zA-Z0-9] (notice there is no NOT) then IsAlphaNumeric = ianRegEx.Test(str) will ALWAYS return true if ANY of those characters exist... Morgoth 02-03-2003, 03:33 AM Thank you whammy. angiras 02-04-2003, 09:13 PM an easy or lazy way is dim _myInt as integer public property isInteger() as boolean get dim _i as integer try _i = cInt(_myInt) return true catch return false end try and get set _myInt = value and set end property if true then it is an integer , if not ... not whammy 02-04-2003, 09:34 PM And how does that account for Alpha characters? angiras 02-04-2003, 09:40 PM yes for string you just use regular Expression but for any other format (date ect.. ) you cabn use that leasy way or even easier Dim MyVar As Object Dim MyCheck As Boolean MyVar = "53" ' Assign value. MyCheck = IsNumeric(MyVar) ' Returns True. ' ... MyVar = "459.95" ' Assign value. MyCheck = IsNumeric(MyVar) ' Returns True. ' ... MyVar = "45 Help" ' Assign value. MyCheck = IsNumeric(MyVar) ' Returns False |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum