#175124 - 2007-03-31 03:40 AM
Re: Input validation
[Re: Gargoyle]
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Silver Platter: Break on
$RegExPattern = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"
do
? "Enter IP Address: "
gets $input
until RegExpTest($RegExPattern, $input, 1)
? "Valid IP address: " + $input
Function RegExpTest($Pattern, $String, $IgnoreCase)
Dim $regEx, $Match, $Matches ; Create variable.
$regEx = createobject("VBscript.RegExp") ; Create a regular expression.
$regEx.Pattern = $Pattern ; Set pattern.
$regEx.IgnoreCase = val($IgnoreCase) ; Set case insensitivity.
$RegExpTest = $regEx.Test($String) ; Execute test search.
EndFunction
Edited by Howard Bullock (2007-03-31 03:43 AM) Edit Reason: Made RegEx string better
|
Top
|
|
|
|
#175133 - 2007-03-31 04:48 PM
Re: Input validation
[Re: Gargoyle]
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
In reaction to the first post, I would think this code is better
Dim $input
CLS
?"input subnet to search?"
Do
Gets $input
Until 255 >= $input AND 0 <= $input
To get the right implicit conversion of $input
|
Top
|
|
|
|
#175152 - 2007-04-02 07:16 AM
Re: Input validation
[Re: Les]
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Thanks Les, it is always nice to get appreciated. To avoid alphabetic input, I would even add a more explicit conversion:
Dim $input
CLS
?"input subnet to search?"
Do
Gets $input
Until 255 >= $input AND 0 <= $input AND $input = CStr(CInt($input))
Hey, that answers the initial question
Edited by Witto (2007-04-02 10:11 AM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|