Skip to content

Commit 3f02f27

Browse files
committed
Simplified domain validation, issue victorjonsson#209 and victorjonsson#204
1 parent 43a15ef commit 3f02f27

File tree

10 files changed

+24
-74
lines changed

10 files changed

+24
-74
lines changed

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.40
13+
* @version 2.2.beta.47
1414
*/
1515
(function($) {
1616

form-validator/file.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.40
13+
* @version 2.2.beta.47
1414
*/
1515
(function($, window) {
1616

form-validator/html5.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @website http://formvalidator.net/
1919
* @license Dual licensed under the MIT or GPL Version 2 licenses
20-
* @version 2.2.beta.40
20+
* @version 2.2.beta.47
2121
*/
2222
(function($, window) {
2323

form-validator/jquery.form-validator.js

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @website http://formvalidator.net/
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 2.2.beta.40
8+
* @version 2.2.beta.47
99
*/
1010
(function($) {
1111

@@ -1369,7 +1369,7 @@
13691369
var emailParts = email.toLowerCase().split('@');
13701370
if( emailParts.length == 2 ) {
13711371
return $.formUtils.validators.validate_domain.validatorFunction(emailParts[1]) &&
1372-
!(/[^\w\+\.\-]/.test(emailParts[0]));
1372+
!(/[^\w\+\.\-]/.test(emailParts[0])) && emailParts[0].length > 0;
13731373
}
13741374

13751375
return false;
@@ -1383,61 +1383,14 @@
13831383
*/
13841384
$.formUtils.addValidator({
13851385
name : 'domain',
1386-
validatorFunction : function(val, $input) {
1387-
1388-
var topDomains = [".com",".org",".net",".int",".edu",".gov",".mil",".ac",".ad",".ae",".af",".ag",".ai",".al",".am",".an",".ao",".aq",".ar",".as",".at",".au",".aw",".ax",".az",".ba",".bb",".bd",".be",".bf",".bg",".bh",".bi",".bj",".bm",".bn",".bo",".bq",".br",".bs",".bt",".bv",".bw",".by",".bz",".ca",".cc",".cd",".cf",".cg",".ch",".ci",".ck",".cl",".cm",".cn",".co",".cr",".cs",".cu",".cv",".cw",".cx",".cy",".cz",".dd",".de",".dj",".dk",".dm",".do",".dz",".ec",".ee",".eg",".eh",".er",".es",".et",".eu",".fi",".fj",".fk",".fm",".fo",".fr",".ga",".gb",".gd",".ge",".gf",".gg",".gh",".gi",".gl",".gm",".gn",".gp",".gq",".gr",".gs",".gt",".gu",".gw",".gy",".hk",".hm",".hn",".hr",".ht",".hu",".id",".ie",".il",".im",".in",".io",".iq",".ir",".is",".it",".je",".jm",".jo",".jp",".ke",".kg",".kh",".ki",".km",".kn",".kp",".kr",".kw",".ky",".kz",".la",".lb",".lc",".li",".lk",".lr",".ls",".lt",".lu",".lv",".ly",".ma",".mc",".md",".me",".mg",".mh",".mk",".ml",".mm",".mn",".mo",".mp",".mq",".mr",".ms",".mt",".mu",".mv",".mw",".mx",".my",".mz",".na",".nc",".ne",".nf",".ng",".ni",".nl",".no",".np",".nr",".nu",".nz",".om",".pa",".pe",".pf",".pg",".ph",".pk",".pl",".pm",".pn",".pr",".ps",".pt",".pw",".py",".qa",".re",".ro",".rs",".ru",".rw",".sa",".sb",".sc",".sd",".se",".sg",".sh",".si",".sj",".sk",".sl",".sm",".sn",".so",".sr",".ss",".st",".su",".sv",".sx",".sy",".sz",".tc",".td",".tf",".tg",".th",".tj",".tk",".tl",".tm",".tn",".to",".tp",".tr",".tt",".tv",".tw",".tz",".ua",".ug",".uk",".us",".uy",".uz",".va",".vc",".ve",".vg",".vi",".vn",".vu",".wf",".ws",".ye",".yt",".yu",".za",".zm",".zr",".zw",".academy",".accountants",".active",".actor",".aero",".agency",".airforce",".archi",".army",".associates",".attorney",".auction",".audio",".autos",".band",".bargains",".beer",".best",".bid",".bike",".bio",".biz",".black",".blackfriday",".blue",".boo",".boutique",".build",".builders",".business",".buzz",".cab",".camera",".camp",".cancerresearch",".capital",".cards",".care",".career",".careers",".cash",".catering",".center",".ceo",".channel",".cheap",".christmas",".church",".city",".claims",".cleaning",".click",".clinic",".clothing",".club",".coach",".codes",".coffee",".college",".community",".company",".computer",".condos",".construction",".consulting",".contractors",".cooking",".cool",".country",".credit",".creditcard",".cricket",".cruises",".dad",".dance",".dating",".day",".deals",".degree",".delivery",".democrat",".dental",".dentist",".diamonds",".diet",".digital",".direct",".directory",".discount",".domains",".eat",".education",".email",".energy",".engineer",".engineering",".equipment",".esq",".estate",".events",".exchange",".expert",".exposed",".fail",".farm",".feedback",".finance",".financial",".fish",".fishing",".fitness",".flights",".florist",".fly",".foo",".forsale",".foundation",".fund",".furniture",".futbol",".gallery",".gift",".gifts",".gives",".glass",".global",".gop",".graphics",".green",".gripe",".guide",".guitars",".guru",".healthcare",".help",".here",".hiphop",".hiv",".holdings",".holiday",".homes",".horse",".host",".hosting",".house",".how",".info",".ing",".ink",".insure",".international",".investments",".jobs",".kim",".kitchen",".land",".lawyer",".legal",".lease",".lgbt",".life",".lighting",".limited",".limo",".link",".loans",".lotto",".luxe",".luxury",".management",".market",".marketing",".media",".meet",".meme",".memorial",".menu",".mobi",".moe",".money",".mortgage",".motorcycles",".mov",".museum",".name",".navy",".network",".new",".ngo",".ninja",".ong",".onl",".ooo",".organic",".partners",".parts",".party",".pharmacy",".photo",".photography",".photos",".physio",".pics",".pictures",".pink",".pizza",".place",".plumbing",".poker",".post",".press",".pro",".productions",".prof",".properties",".property",".qpon",".recipes",".red",".rehab",".ren",".rentals",".repair",".report",".republican",".reviews",".rich",".rip",".rocks",".rodeo",".rsvp",".science",".services",".sexy",".shoes",".singles",".social",".software",".solar",".solutions",".space",".supplies",".supply",".support",".surf",".surgery",".systems",".tattoo",".tax",".technology",".tel",".tips",".tires",".today",".tools",".top",".town",".toys",".trade",".training",".travel",".university",".vacations",".vet",".villas",".vision",".vodka",".vote",".voting",".voyage",".wang",".watch",".webcam",".website",".wed",".wiki",".works",".world",".wtf",".xxx",".xyz",".zone",".maison",".abogado",".casa",".gratis",".juegos",".soy",".tienda",".uno",".viajes",".haus",".immobilien",".jetzt",".kaufen",".reise",".reisen",".schule",".versicherung",".desi",".shiksha",".immo",".moda",".voto",".bar",".coop",".enterprises",".industries",".institute",".ltda",".pub",".realtor",".reit",".rest",".restaurant",".sarl",".ventures",".capetown",".durban",".joburg",".miami",".nyc",".quebec",".rio",".vegas",".asia",".krd",".nagoya",".okinawa",".ryukyu",".taipei",".tatar",".tokyo",".yokohama",".alsace",".bayern",".berlin",".brussels",".budapest",".bzh",".cat",".cologne",".cymru",".eus",".frl",".gal",".gent",".hamburg",".koeln",".london",".madrid",".moscow",".nrw",".paris",".ruhr",".saarland",".scot",".tirol",".vlaanderen",".wales",".wien",".kiwi",".melbourne",".sydney",".allfinanz",".android",".aquarelle",".axa",".bloomberg",".bmw",".bnpparibas",".cal",".caravan",".cern",".chrome",".citic",".crs",".cuisinella",".dnp",".dvag",".emerck",".everbank",".firmdale",".flsmidth",".frogans",".gbiz",".gle",".globo",".gmail",".gmo",".gmx",".google",".ibm",".kred",".lacaixa",".latrobe",".lds",".mango",".mini",".monash",".mormon",".neustar",".nexus",".nhk",".nra",".otsuka",".ovh",".pohl",".praxi",".prod",".sca",".scb",".schmidt",".sohu",".spiegel",".suzuki",".tui",".uol",".williamhill",".wme",".wtc",".yandex",".youtube"],
1389-
ukTopDomains = ['co', 'me', 'ac', 'gov', 'judiciary','ltd', 'mod', 'net', 'nhs', 'nic', 'org', 'parliament', 'plc', 'police', 'sch', 'bl', 'british-library', 'jet','nls'],
1390-
dotPos = val.lastIndexOf('.'),
1391-
domain = val.substring(0, dotPos),
1392-
topDomain = val.substring(dotPos, val.length),
1393-
isXN = topDomain.indexOf('.xn--') == 0,
1394-
hasTopDomain = isXN;
1395-
1396-
if( !isXN ) {
1397-
for (var i = 0; i < topDomains.length; i++) {
1398-
if (topDomains[i] === topDomain) {
1399-
if(topDomain==='.uk') {
1400-
//Run Extra Checks for UK Domain Names
1401-
var domainParts = val.split('.');
1402-
var tld2 = domainParts[domainParts.length-2];
1403-
for(var j = 0; j < ukTopDomains.length; j++) {
1404-
if(ukTopDomains[j] === tld2) {
1405-
hasTopDomain = true;
1406-
break;
1407-
}
1408-
}
1409-
1410-
if(hasTopDomain)
1411-
break;
1412-
1413-
} else {
1414-
hasTopDomain = true;
1415-
break;
1416-
}
1417-
}
1418-
}
1419-
}
1420-
1421-
if (!hasTopDomain) {
1422-
return false;
1423-
} else if (dotPos < 2 || dotPos > 57) {
1424-
return $.inArray(val, ['i.net', 'q.com', 'q.net', 'x.com', 'x.org', 'z.com', 'w.org']) > -1;
1425-
} else {
1426-
var firstChar = domain.substring(0, 1),
1427-
lastChar = domain.substring(domain.length - 1, domain.length);
1428-
1429-
if ( firstChar === '-' || firstChar === '.' || lastChar === '-' || lastChar === '.') {
1430-
return false;
1431-
}
1432-
if (domain.split('..').length > 1) {
1433-
return false;
1434-
}
1435-
if (encodeURI(domain.replace(/%/g, '&')).toLowerCase().replace(/[-%\da-z\.]/g, '') !== '') {
1436-
return false;
1437-
}
1438-
}
1439-
1440-
return true;
1386+
validatorFunction : function(val) {
1387+
return val.length > 0 &&
1388+
val.length <= 253 && // Including sub domains
1389+
!(/[^a-zA-Z0-9]/.test(val.substr(-2))) &&
1390+
!(/[^a-zA-Z]/.test(val.substr(0,1))) &&
1391+
!(/[^a-zA-Z0-9\.\-]/.test(val)) &&
1392+
val.split('..').length == 1 &&
1393+
val.split('.').length > 1;
14411394
},
14421395
errorMessage : '',
14431396
errorMessageKey: 'badDomain'

form-validator/jquery.form-validator.min.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/location.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.40
13+
* @version 2.2.beta.47
1414
*/
1515
(function($) {
1616

form-validator/qunit.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
{val: 'valid-domain@website.COM', isValid : true},
117117
{val: 'asdsdsd@sdsd.co.uk', isValid : true},
118118
{val: 'sasas@sdsd.xxx', isValid : true},
119-
{val: 'sasas@sdsd.xxz', isValid : false},
119+
{val: 'sasas@sdsd.xxz', isValid : true},
120120
{val: '@sdsd.xxz', isValid : false},
121121
{val: 'sasas@', isValid : false},
122122
{val: 'sasas.se', isValid : false},
@@ -139,13 +139,9 @@
139139
{val: 'klsdmfklsmdf', isValid: false},
140140
{val: 'http://google.se', isValid: true},
141141
{val: 'https://google.se/test/?arge=hej_&arg[]=123', isValid: true},
142-
{val: 'http://google.xxx/test/test.jsp', isValid: true},
143-
{val: 'http://google.xxy', isValid: false},
144-
{val: 'http://google.xxy/test/test.jsp', isValid: false},
145142
{val: 'http://google.test.de', isValid: true},
146143
{val: 'http://test.xn--fiqz9s', isValid: true},
147144
{val: 'http://test.youtube', isValid: true},
148-
{val: 'http://test.youtubez', isValid: false},
149145
{val: 'http://google.test.co.uk/', isValid: true}
150146
];
151147

@@ -166,15 +162,17 @@
166162
{val:'domain.xxx', isValid:true},
167163
{val:'domain.com', isValid:true},
168164
{val:'www.domain.com', isValid:true},
165+
{val:'test.xn--fiqz9s', isValid:true},
166+
{val:'test..xn--fiqz9s', isValid:false},
169167
{val:'q.com', isValid:true},
170-
{val:'v.com', isValid:false},
171168
{val:'amazone.website.tippit.de', isValid:true},
172169
{val:'amazone.website.co.uk', isValid:true},
173170
{val:'http://domain.se', isValid:false},
174171
{val:'http://www.domain.se', isValid:false},
175172
{val:'http://www.domain.se/', isValid:false},
176173
{val:'domain.com/', isValid:false},
177-
{val:'', isValid:false}
174+
{val:'', isValid:false},
175+
{val:'asdfasdf', isValid:false}
178176
];
179177

180178
$.each(links, function(i, obj) {

form-validator/security.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - cvv
1414
*
1515
* @website http://formvalidator.net/#security-validators
16-
* @version 2.2.beta.40
16+
* @version 2.2.beta.47
1717
*/
1818
(function($, window) {
1919

form-validator/sweden.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @website http://formvalidator.net/#swedish-validators
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 2.2.beta.40
16+
* @version 2.2.beta.47
1717
*/
1818
(function($, window) {
1919

form-validator/uk.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @website http://formvalidator.net/#uk-validators
1111
* @license Dual licensed under the MIT or GPL Version 2 licenses
12-
* @version 2.2.beta.40
12+
* @version 2.2.beta.47
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'ukvatnumber',

0 commit comments

Comments
 (0)