|
|
|
ขอโค้ด JavaScript ที่ใช้เช็ค URL หน่อยครับเนื่องจากตัวอย่างที่มีดูแล้วนำมาเขียนไม่ได้เลยครับ |
|
|
|
|
|
|
|
Code (JavaScript)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<form name="frmMain" action="" method="post" OnSubmit="return chkSubmit()">
<script language="javascript">
function CheckValidUrl(strUrl){
var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return RegexUrl.test(strUrl);
}
function chkSubmit()
{
if(CheckValidUrl(document.frmMain.txtUrl.value)==false)
{
alert('Please enter new url');
return false;
}
}
</script>
Input URL <input type="text" name="txtUrl" value="">
<input type="submit" name="butSubmit" value="Check">
</form>
</body>
</html>
|
|
|
|
|
Date :
2011-05-09 17:42:30 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อีกตัวอย่างครับ
Code (JavaScript)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<form name="frmMain" action="" method="post" OnSubmit="return chkSubmit()">
<script language="javascript">
function CheckValidUrl(strUrl){
var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
return RegExp.test(strUrl);
}
function chkSubmit()
{
if(CheckValidUrl(document.frmMain.txtUrl.value)==false)
{
alert('Please enter new url');
return false;
}
}
</script>
Input URL <input type="text" name="txtUrl" value="">
<input type="submit" name="butSubmit" value="Check">
</form>
</body>
</html>
|
|
|
|
|
Date :
2011-05-09 17:50:19 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|