asp.net mvc dataannotation validating url

后端 未结 9 711
离开以前
离开以前 2021-02-04 05:23

can some one tell me how can i validate a url like http://www.abc.com

9条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 05:59

    Use a regular expression data annotation, and use a regex like:

    http://www\.\w+\.(com|net|edu|org)
    

    Depending on what you need to validate; are you requiring http: or are you requiring www.? So that could change the regular expression, if optional, to:

    (http://)?(www\.)?\w+\.(com|net|edu|org)
    

提交回复
热议问题