From: Tom Tyson on
Hey guys,

I use this function:

Function ValidateField(strInput, txtRegExp)
Set re = new regexp
re.Pattern = txtRegExp
re.IgnoreCase=true
ValidateField=re.Test(strInput)
set re = Nothing
End Function

to validate text field values against regular expressions. I'm no wizard
when it comes to regexps. I got 99% of the text fields covered, except for
this one:

The text field:

* can be empty
* can be a single alphanumeric string with up to 32 characters
* must not contain any spaces or any non-alphanumeric characters except
underscore, dash and comma
* can be a comma separated list of up to 10 strings as defined above, e.g .
"entry1,entry2,veryveryverylongentry3"


Can this be done by a regular expression?

Tom


From: Mayayana on
I don't use RegExp, but in case you don't
find an answer you can also use a simple
function:

Function IsValid(s1)
Dim i2, Asc1
IsValid = False
If Len(s1) > 32 Then Exit Function
If Len(s1) = 0 Then IsValid = True: Exit Function
For i2 = 1 to Len(s1)
Asc1 = Asc(mid(s1, i2, 1))
Select Case Asc1
Case 44, 45, 95
'--
Case Else
If ((Asc1 > 64) And (Asc1 < 91)) Or ((Asc1 > 96) And (Asc1 <
123)) Or ((Asc1 > 47) And (Asc1 < 58)) Then
'--
Else
Exit Function
End If
End Select
Next
IsValid = True
End Function

|
| I use this function:
|
| Function ValidateField(strInput, txtRegExp)
| Set re = new regexp
| re.Pattern = txtRegExp
| re.IgnoreCase=true
| ValidateField=re.Test(strInput)
| set re = Nothing
| End Function
|
| to validate text field values against regular expressions. I'm no wizard
| when it comes to regexps. I got 99% of the text fields covered, except for
| this one:
|
| The text field:
|
| * can be empty
| * can be a single alphanumeric string with up to 32 characters
| * must not contain any spaces or any non-alphanumeric characters except
| underscore, dash and comma
| * can be a comma separated list of up to 10 strings as defined above, e.g
..
| "entry1,entry2,veryveryverylongentry3"
|
|
| Can this be done by a regular expression?
|
| Tom
|
|


From: Steve on
Tom Tyson wrote:
>
> The text field:
>
> * can be empty
> * can be a single alphanumeric string with up to 32 characters
> * must not contain any spaces or any non-alphanumeric characters
> except underscore, dash and comma

Doesn't "alphanumeric characters" exclude underscore and dash? (Also,
comma; but commas are used a separators in the next point.) The pattern
will assume that "alphanumeric characters" includes underscores and
dashes.

> * can be a comma separated list of up to 10 strings as defined above,
> e.g . "entry1,entry2,veryveryverylongentry3"

txtRegExp = "^(?:[0-9a-z\-_]{1,32}(?:,[0-9a-z\-_]{1,32}){0,9})?$"

--
Steve

I don't divide the world into the weak and the strong, or the successes
and the failures, those who make it or those who don't. I divide the
world into learners and non-learners. -Benjamin Barber


From: ekkehard.horner on
Tom Tyson schrieb:
> Hey guys,
>
> I use this function:
>
> Function ValidateField(strInput, txtRegExp)
> Set re = new regexp
> re.Pattern = txtRegExp
> re.IgnoreCase=true
> ValidateField=re.Test(strInput)
> set re = Nothing
> End Function
>
> to validate text field values against regular expressions. I'm no wizard
> when it comes to regexps. I got 99% of the text fields covered, except for
> this one:
>
> The text field:
>
> * can be empty
> * can be a single alphanumeric string with up to 32 characters
> * must not contain any spaces or any non-alphanumeric characters except
> underscore, dash and comma
> * can be a comma separated list of up to 10 strings as defined above, e.g .
> "entry1,entry2,veryveryverylongentry3"
>
>
> Can this be done by a regular expression?

Using Split to get the comma separated items and a Regexp to check
each item is easier, less errorprone, and simpler to adjust. (e.g.
do you consider "," as a valid string containing two empty items?)

Use a function like:

Function checkTTyson( sTxt, reValid )
checkTTyson = Array( True, "", Array() )
If "" <> sTxt Then
Dim aParts : aParts = Split( sTxt, "," )
Dim nUB : nUB = UBound( aParts )
If 9 < nUB Then
checkTTyson = Array( False, "too many (" & (nUB + 1) & ")
elements" )
Else
Dim sPart
For Each sPart In aParts
If Not reValid.Test( sPart ) Then
checkTTyson = Array( False, "(frs) bad element >|" &
sPart & "|<" )
Exit Function
End If
Next
checkTTyson = Array( True, "", aParts )
End If
End If
End Function

with a test script like:

Dim aTests : aTests = Array( _
Array( "empty", "", True ) _
, Array( "one ,", ",", False ) _
, Array( "bad symbols (single)", "a$%b", False ) _
, Array( "bad symbols (multi)", "a,b,(,c", False ) _
, Array( "single simple", "a1_-", True, Array( "a1_-" ) ) _
, Array( "multi simple", "1,2,3", True ) _
, Array( "multi 10 items", "1,2,3,4,5,6,7,8,9,10", True ) _
, Array( "multi too many", "1,2,3,4,5,6,7,8,9,10,11", False ) _
)
Dim reValid : Set reValid = New RegExp
reValid.Pattern = "^[\w-]+$"
Dim aTest
For Each aTest In aTests
WScript.Echo "-----------", aTest( 0 )
WScript.Echo ">|" & aTest( 1 ) & "|<"
Dim aRet : aRet = checkTTyson( aTest( 1 ), reValid )
WScript.Echo "Valid:", aRet( 1 ), CStr( aRet( 0 ) ), CStr( aTest(
2 ) = aRet( 0 ) )
If aRet( 0 ) Then WScript.Echo "Items: >|" & Join( aRet( 2 ),
"|<>|" ) & "|<"
WScript.Echo
Next

output:

==============================================================
testTTyson00 - validate/parse Tom Tyson's data (02/split)
--------------------------------------------------------------
----------- empty
>||<
Valid: True True
Items: >||<

----------- one ,
>|,|<
Valid: (frs) bad element >||< False True

----------- bad symbols (single)
>|a$%b|<
Valid: (frs) bad element >|a$%b|< False True

----------- bad symbols (multi)
>|a,b,(,c|<
Valid: (frs) bad element >|(|< False True

----------- single simple
>|a1_-|<
Valid: True True
Items: >|a1_-|<

----------- multi simple
>|1,2,3|<
Valid: True True
Items: >|1|<>|2|<>|3|<

----------- multi 10 items
>|1,2,3,4,5,6,7,8,9,10|<
Valid: True True
Items: >|1|<>|2|<>|3|<>|4|<>|5|<>|6|<>|7|<>|8|<>|9|<>|10|<

----------- multi too many
>|1,2,3,4,5,6,7,8,9,10,11|<
Valid: too many (11) elements False True




From: Kenneth A. Larsen on

"Mayayana" <mayayana(a)invalid.nospam> wrote in message
news:i316um$p7g$1(a)news.eternal-september.org...
>I don't use RegExp, but in case you don't
> find an answer you can also use a simple
> function:
>
> Function IsValid(s1)
> Dim i2, Asc1
> IsValid = False
> If Len(s1) > 32 Then Exit Function
> If Len(s1) = 0 Then IsValid = True: Exit Function
> For i2 = 1 to Len(s1)
> Asc1 = Asc(mid(s1, i2, 1))
> Select Case Asc1
> Case 44, 45, 95
> '--
> Case Else
> If ((Asc1 > 64) And (Asc1 < 91)) Or ((Asc1 > 96) And (Asc1 <
> 123)) Or ((Asc1 > 47) And (Asc1 < 58)) Then
> '--
> Else
> Exit Function
> End If
> End Select
> Next
> IsValid = True
> End Function
>
> |
> | I use this function:
> |
> | Function ValidateField(strInput, txtRegExp)
> | Set re = new regexp
> | re.Pattern = txtRegExp
> | re.IgnoreCase=true
> | ValidateField=re.Test(strInput)
> | set re = Nothing
> | End Function
> |
> | to validate text field values against regular expressions. I'm no wizard
> | when it comes to regexps. I got 99% of the text fields covered, except
> for
> | this one:
> |
> | The text field:
> |
> | * can be empty
> | * can be a single alphanumeric string with up to 32 characters
> | * must not contain any spaces or any non-alphanumeric characters except
> | underscore, dash and comma
> | * can be a comma separated list of up to 10 strings as defined above,
> e.g
> .
> | "entry1,entry2,veryveryverylongentry3"
> |
> |
> | Can this be done by a regular expression?
> |
> | Tom
> |
> |
>
>