开发者

How to control a url entered to MaskedTextBox

开发者 https://www.devze.com 2023-04-04 05:59 出处:网络
I have added a MaskedTextBox control to my form and i wannt users to enter a vali开发者_如何学God url to control. What mask code i enter to control?you don\'t really want to mask a url, as I believe m

I have added a MaskedTextBox control to my form and i wannt users to enter a vali开发者_如何学God url to control. What mask code i enter to control?


you don't really want to mask a url, as I believe masking doesn't support regex, masks are set in stone, there are no wild cards.

for example you may have a mask for: aaa.aaaaaa.aaa

this will only work for something like www.google.com

masks are ideal for situations where you know the fixed length such as a date or zip code.

websites can be change from site to site in length. It would be much better to have a plain textbox on your form and use Regular Expression to validate that it is a website, although that is also not an easy task. as there are many different variations for valid websites.

something like this in regex can check for websites:

^((nntp|sftp|ftp(s)?|http(s)?|gopher|news|file|telnet):\/\/)?(([a-zA-Z0-9\._-]*([a-zA-Z0-9]\.[a-zA-Z0-9])[a-zA-Z]{1,6})|(([0-9]{1,3}\.){3}[0-9]{1,3}))(:\d+)?(\/[^:][^\s]*)?$

more can be found here: http://regexlib.com/Search.aspx?k=URL&c=-1&m=-1&ps=100

0

精彩评论

暂无评论...
验证码 换一张
取 消