如何验证文本框只允许网站网址 [英] How to validate Textbox to allow only website url

查看:58
本文介绍了如何验证文本框只允许网站网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要验证文本框,以便它只能将网站网址添加到域代码中。

例如用户必须将网站网址插入http://www.google.com。



如果用户插入http://www.codeproject.com/Articles/ 334310 /了解-ASP-NET-Validation-Techniques然后它不应该允许。



允许: - http://www.google.com



不允许: - http://www.codeproject.com/Articles/334310/Understanding-ASP-NET-Validation-Techniques



请帮助。

解决方案

正则表达式解决方案太过琐碎了;我认为没有必要讨论它;只学习正则表达式的基础知识。



一个明显的解决方案是将URL部分保留到域名(或与某个基本子目录相同)不可编辑。允许仅编辑不可编辑部分右侧的文本。这不是很简单吗?



我可以建议一些替代方案吗?我认为整个想法都很糟糕。对于用户来说,它实际上是不可用的。最好只显示所有有效的URL(树视图是相当不错的选项),因此用户对URL的选择将减少到所需节点的选择。



如果你分享了你的奇怪,非常奇怪的要求,我或许可以给你更好的建议。



-SA

Hi,
I need to validate textbox so that it can only take website url up-to domain code only.
For e.g. User must insert website url as "http://www.google.com".

If user insert "http://www.codeproject.com/Articles/334310/Understanding-ASP-NET-Validation-Techniques" then it should not allow.

Allowed:-"http://www.google.com"

Not Allowed:-"http://www.codeproject.com/Articles/334310/Understanding-ASP-NET-Validation-Techniques"

Please help.

解决方案

The Regex solution is way too trivial; I don't think there is a need to discuss it; just learn Regex basics.

One obvious solution is to leave the URL part up to the domain name (or the same with some base sub-directory) not editable. Allow to edit only the text on right of the non-editable part. Isn't that simple?

May I suggest some alternatives? I think the whole idea is bad. For the user, it would be practically unusable. It would be better that you simply display all valid URLs (tree view would be fairly good option), so the user's choice of URL will be reduced to selection of desired node.

Perhaps I would be able to give you better advice if you shared the ultimate goal of you weird, really weird requirement.

—SA


这篇关于如何验证文本框只允许网站网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆