Click to See Complete Forum and Search --> : Validation for domain name & IPAddress


shanuragu
10-22-2003, 08:23 AM
Hi
Can any one please tell how to validate for domain name (www.somename.com) and IP Address (111.333.99.34)

Conditions for IP Address is

1. only four "." are allowed & is a must
2. numbers should not cross 255
3. no other charecters other than "." is allowed

shara

Charles
10-22-2003, 12:29 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<script type="text/javascript">
<!--
String.prototype.isIPAddress = function () {if (!this.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) return false; for (var i=1; i<=4; i++) {if (RegExp['$' + i] > 255) return false}; return true}
// -->
</script>

<form action="">
<div>
<label>IP Address<input type="text" onchange="if (!this.value.isIPAddress()) {alert('That does not appear to be a valid IP Address.'); this.value=''; this.focus()}"></label>
<button type="submit">Submit</button>
</div>
</form>

shanuragu
10-22-2003, 10:55 PM
Thanks Charles

But how to validate Domain name ie www.wesitename.com

shara

Charles
10-23-2003, 04:46 AM
If you can tell me what constitutes a valid domain name then I can write your script.

shanuragu
10-23-2003, 07:09 AM
It is nothing but any web site address, it should be in
www.websitename.com (com/co/org...) format

shara

Charles
10-23-2003, 07:18 AM
Originally posted by shanuragu
It is nothing but any web site address, it should be in
www.websitename.com (com/co/org...) format

shara We need a lot more to go on than that. What characters are allowed? What are the length restrictions? What about case? Do you want to require the tripple w? What about the country codes?

shanuragu
10-23-2003, 08:13 AM
Sorry!!

here are the conditions :
format is www.sitename.com

1. two "." are must
2. www is a must
3. last word should always be more than one letter (co,com...) & only charecters
4. Website name can be alphanumeric, no limit for wesite name length
5. It should start with www only


shara

AdamGundry
10-23-2003, 11:57 AM
I think this should do it:

String.prototype.isDomainName = function () {return this.match(/^www\.\w{2,}\.[a-zA-Z]{2,}$/)}

Adam