本文介绍了如何验证字符串是否有效Aspx Url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我是初级开发人员,所以我还没有选择正则表达式(> o<)。 在目前的情况下,我想检查SharePoint URL是否有效。 在验证sharepoint url之前,我想验证它是否是正确的aspx url ... 例如: http:// localhost:8181 / Test_ASPX_To_HTML / test0.aspx (有效) http://localhost/Test_ASPX_To_HTML/test1.aspx (有效) https://www.helloworld.com/Test_ASPX_To_HTML/test2.aspx (有效) https://www.helloworld.co.jp/ Test_ASPX_To_HTML / test3.aspx (有效) http://www.helloworld.org.hk/Test_ASPX_To_HTML/test4.aspx (有效) https://www.helloworld.tv:1233/Test_ASPX_To_HTML/test5.aspx (有效) https:// localhost:8181 / Test_ASPX_To_HTML / test6.aspxx (无效) https://localhost:8181/Test_ASPX_To_HTML/test7.asp (无效) https:// localhost:8181 / Test_ASPX_To_HTML / test8.asax (无效) https:// localhost:8181 \Test_ASPX_To_HTML \ test9.asax (无效) http://[email protected] (无效) HTTP://!〜!@#$%^^&放大器; *(((((((((((((的.aspx (无效) http:// localhost:8181 / Test_ASPX_To_HTML / test10.aspx θA = 1 (有效) http:// localhost :8181 / Test_ASPX_To_HTML / test11.aspx?a = 2& b = 3 (有效) http://www.test.net/Test_ASPX_To_HTML/test12.aspx?a=2&b=3&c=4 (有效) http://www.test.net\Test_ASPX_To_HTML\test13.aspx?a=2&b=3&c=4 (无效) www.test.net/Test_ASPX_To_HTML/test14.aspx?a=2&b=3&c=4 (无效) ftp://www.test.net/Test_ASPX_To_HTML/test15.aspx (无效) HTTP://www.test.net\Test_ASPX_To_HTML\test16.aspx A = 2和b = 3和C = 4 (无效) 并且它必须没有任何无效的字符。等。 一一 我的简单编码如下:In current situation, I want to check SharePoint URL is valid or not. Before verify  the sharepoint url, I want to verify it is correct aspx url...For example:http://localhost:8181/Test_ASPX_To_HTML/test0.aspx (Valid)http://localhost/Test_ASPX_To_HTML/test1.aspx  (Valid)https://www.helloworld.com/Test_ASPX_To_HTML/test2.aspx (Valid)https://www.helloworld.co.jp/Test_ASPX_To_HTML/test3.aspx (Valid)http://www.helloworld.org.hk/Test_ASPX_To_HTML/test4.aspx (Valid)https://www.helloworld.tv:1233/Test_ASPX_To_HTML/test5.aspx (Valid)https://localhost:8181/Test_ASPX_To_HTML/test6.aspxx  (Invalid)https://localhost:8181/Test_ASPX_To_HTML/test7.asp  (Invalid)https://localhost:8181/Test_ASPX_To_HTML/test8.asax  (Invalid)https://localhost:8181\Test_ASPX_To_HTML\test9.asax  (Invalid)http://[email protected]  (Invalid)http://~!@#$%^^&*(((((((((((((.aspx  (Invalid)http://localhost:8181/Test_ASPX_To_HTML/test10.aspx?a=1  (Valid)http://localhost:8181/Test_ASPX_To_HTML/test11.aspx?a=2&b=3 (Valid)http://www.test.net/Test_ASPX_To_HTML/test12.aspx?a=2&b=3&c=4 (Valid)http://www.test.net\Test_ASPX_To_HTML\test13.aspx?a=2&b=3&c=4 (Invalid)www.test.net/Test_ASPX_To_HTML/test14.aspx?a=2&b=3&c=4  (Invalid)ftp://www.test.net/Test_ASPX_To_HTML/test15.aspx  (Invalid)http://www.test.net\Test_ASPX_To_HTML\test16.aspx?a=2&b=3&c=4 (Invalid)And it must not have any invalid char. etc.My simple coding as follows: if (strTargetASPX.Substring(0 ,4)。ToLower()。Equals(" http" )&&if (strTargetASPX.Substring(0, 4).ToLower().Equals("http") && strTargetASPX.Substring(strTargetASPX .Length - 4,4).ToLower()。Equals(" aspx" )&& // Wrong    strTargetASPX.Substring(strTargetASPX.Length - 4, 4).ToLower().Equals("aspx") && //Wrong strTargetASPX.IndexOf("!" )< 0&&                            strTargetASPX.IndexOf("!") < 0 && strTargetASPX.IndexOf(" @" ; )< 0&&                            strTargetASPX.IndexOf("@") < 0 && strTargetASPX.IndexOf("#" )< 0&&                            strTargetASPX.IndexOf("#") < 0 && strTargetASPX.IndexOf(" $" )< 0&&                            strTargetASPX.IndexOf("$") < 0 && strTargetASPX.IndexOf(" ^" )< 0&&                            strTargetASPX.IndexOf("^") < 0 && strTargetASPX.IndexOf(" *" )< 0&&                            strTargetASPX.IndexOf("*") < 0 && strTargetASPX.IndexOf("(&)< 0&&                            strTargetASPX.IndexOf("(") < 0 && strTargetASPX.IndexOf(")" )< 0&&                            strTargetASPX.IndexOf(")") < 0 && strTargetASPX.IndexOf(" - " )< 0&&                            strTargetASPX.IndexOf("-") < 0 && strTargetASPX.IndexOf(" +" )< 0&&                            strTargetASPX.IndexOf("+") < 0 && strTargetASPX.IndexOf( @" \" )< 0&&                            strTargetASPX.IndexOf(@"\") < 0 && strTargetASPX.IndexOf(" \"" )< 0&&                            strTargetASPX.IndexOf("\"") < 0 && strTargetASPX.IndexOf(" ;;" )< 0&&                            strTargetASPX.IndexOf(";") < 0 && strTargetASPX.IndexOf(" |" )< 0&&                            strTargetASPX.IndexOf("|") < 0 && strTargetASPX.IndexOf(" [" )< 0&&                            strTargetASPX.IndexOf("[") < 0 && strTargetASPX.IndexOf("]" )< 0&&                            strTargetASPX.IndexOf("]") < 0 && strTargetASPX.IndexOf(" {" )< 0&&                            strTargetASPX.IndexOf("{") < 0 && strTargetASPX.IndexOf("}" )< 0&&                            strTargetASPX.IndexOf("}") < 0 && strTargetASPX.IndexOf("`" )< 0                            strTargetASPX.IndexOf("`") < 0 ) { //做点什么      //Do something } 我不确定上面的 检查是否完全正确(至少不能通过子串检查aspx,它与aspx不匹配?a = 1& b = 2等。)因此,我想通过正则表达式获得有关最佳实践的建议。 你能帮帮我吗?And I’m not sure the above checking is exactly correct or not (at least cannot check aspx by using Substring, it cannot match the aspx?a=1&b=2 etc.), therefore, I would like to get your advice for best practices with regular expressions. Could you please help me?推荐答案查看我的博客 http://lamahashim.blogspot.com/2009/06/validating-url-using-c。 htmlCheck my blog http://lamahashim.blogspot.com/2009/06/validating-url-using-c.html 这篇关于如何验证字符串是否有效Aspx Url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-21 13:52