Connecting Tech Pros Worldwide Forums | Help | Site Map

subdomain validation

Newbie
 
Join Date: Dec 2008
Posts: 29
#1: Feb 13 '09
How to validate "subdomain" in atextfiled in coldfusion?

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Feb 13 '09

re: subdomain validation


What do you mean by a subdomain? Can you explain with an example. Some code might also help.
Newbie
 
Join Date: Dec 2008
Posts: 29
#3: Feb 13 '09

re: subdomain validation


these are rules to create Sub-Domain Names
Sub-Domain Names

A Sub-Domain Name does not form part of a Registered Domain Name, therefore the rules laid down by the Registrar do not apply.

The characters you can choose from:

* A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
* 1 2 3 4 5 6 7 8 9 0
* Hyphen (-)
* An address must begin and end with an alphanumeric character. Punctuation characters must not be placed together
* Sub-Domain names can contain letters, numbers or hyphens (-), NO spaces or other characters are allowed.
me have lot fdoubts in tht...is more than 2 Hyphen possible? etc..i have to validate thesein coldfusion
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Feb 13 '09

re: subdomain validation


You can use a regular expression to make the checks in one go. See this link.
Newbie
 
Join Date: Dec 2008
Posts: 29
#5: Feb 16 '09

re: subdomain validation


K thanks

<cfset result = REMatch("/^[a-zA-Z0-9\-]*?$/",arguments.subdomain)>



i used this code for checking subdomain validation. but always getting empty array....hw can i?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Feb 16 '09

re: subdomain validation


Why do you have a ? in there? Can you give an example of input (arguments.subdomain)?
Newbie
 
Join Date: Dec 2008
Posts: 29
#7: Feb 16 '09

re: subdomain validation


arguments.subdomain is test123
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#8: Feb 16 '09

re: subdomain validation


The regular expression will not match all the conditions that you specified in an earlier post. For a start, try using a +, e.g.
Expand|Select|Wrap|Line Numbers
  1. ^[a-z0-9\-]+$
Note that REMatch is case-insensitive so there's no need to specify different cases.
Newbie
 
Join Date: Dec 2008
Posts: 29
#9: Feb 16 '09

re: subdomain validation


ok thanks ..
i have to satisy there two condition also
*An address must begin and end with an alphanumeric character. Punctuation characters must not be placed together
* Sub-Domain names can contain letters, numbers or hyphens (-), NO spaces or other characters are allowed.
how can this also possible with ?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#10: Feb 16 '09

re: subdomain validation


The second condition is already satisfied. For the first condition, you can add a alphanumeric pattern at the beginning and the end:
Expand|Select|Wrap|Line Numbers
  1. /^[a-z0-9][a-z0-9\-]+[a-z0-9]$/
You'll need to add a bit more to ensure that the hyphen doesn't appear more than once together.
Newbie
 
Join Date: Dec 2008
Posts: 29
#11: Feb 16 '09

re: subdomain validation


<cfscript>
result = REMatch("/^[a-z0-9][a-z0-9\-]+[a-z0-9]$/",arguments.Webaddress);
</cfscript>

<cfdump var="#result #"> always getting empty array..
i test with test,test12t etc ....stil sme probs
Newbie
 
Join Date: Dec 2008
Posts: 29
#12: Feb 16 '09

re: subdomain validation


i remove staring / and eng /.then it works....

<cfscript>


result = REMatch("^[a-z0-9][a-z0-9\-]+[a-z0-9]$",arguments.Webaddress);
</cfscript>


how to avoid continous repetaion of hyphn?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#13: Feb 16 '09

re: subdomain validation


There are a number of ways, e.g.
Expand|Select|Wrap|Line Numbers
  1. ^\w+(\-?\w)*\w+$
Note: \w is an escape sequence for alphanumeric characters. You could also use [:alnum:] (a character class).
Newbie
 
Join Date: Dec 2008
Posts: 29
#14: Feb 16 '09

re: subdomain validation


Now it workg fine...ok thank u very muchhhh
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#15: Feb 16 '09

re: subdomain validation


You're welcome. Glad it's working :)
Reply