|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Validating Input for new person to vb
hello,
im very new to vb and am making a little program where a user enters a url, i need to be able to validate it, much like a perl regular expression.. does something like this exist in vb? all it needs to do is make sure they have http://(optional www)a hostname and a 3 letter tld. with no file or folder following that. if someone could show me some code or point me to a tutorial id appreciate it. |
|
#2
|
|||
|
|||
|
You can add the Microsoft Scripting Runtime to your vb6 project and use the VBScript RegEx object to do RegEx-type validations.
http://msdn.microsoft.com/library/e...vsobjRegExp.asp |
|
#3
|
|||
|
|||
|
hi, thanks for the article, but I guess I dont have a build in object called regexp or somethign..
the code i put in is: Function RegExpTest(patrn, strng) Dim regEx, Match, Matches ' Create variable. Set regEx = New RegExp ' Create a regular expression. regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Set case insensitivity. regEx.Global = True ' Set global applicability. Set Matches = regEx.Execute(strng) ' Execute search. For Each Match In Matches ' Iterate Matches collection. RetStr = RetStr & "Match found at position " RetStr = RetStr & Match.FirstIndex & ". Match Value is '" RetStr = RetStr & Match.Value & "'." & vbCrLf Next RegExpTest = RetStr End Function and when i try to compile it highlights New RegExp on line 3 of the function and says user-defined type is not defined... i guess this means I dont have the regexp objects in my vb version?? im running vb6 enterprise edition and created an enterprise project... any more help or code is appreciated. i come from c, php, and java so vb still is looking strange and confusing in my second week of it. thanks |
|
#4
|
|||
|
|||
|
You have to add a reference in your project to the Microsoft Scripting Runtime. The RegEx object is an object of VB Script, not VB itself.
|
|
#5
|
|||
|
|||
|
ok,, how do i do that?
|
|
#6
|
|||
|
|||
|
If you have VB6, click Project - References and add the scripting runtime.
|
|
#7
|
|||
|
|||
|
OK! It's a good idea!
Thank U to Doug G. |
|
#8
|
|||
|
|||
|
Here is an example that I came up with that partially works but fails sometimes..
RegExpTest("^http://+.[a-z0-9.]+.[a-z0-9\-.]+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo| br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|d o|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt| gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|k y|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv| mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro |ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg| th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|z w)$",txtUrl.Text) sometiems will work but i have a feeling the problem is with the string concatenation in their. im used to perl regular expressions and vb's are a little different, if someone could fix that id appreciate it... Last edited by drew010 : September 13th, 2003 at 11:02 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Validating Input for new person to vb |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|