regex abc.com

regex match

by ozzymcduff

HTML

<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-2.3.2.css">
<script src="//code.jquery.com/qunit/qunit-2.3.2.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

JavaScript

/*
^ ( notDot middle+ notDot 
     | notDot {1,2} ) $
*/
var notD = "[^.\/\\\\!$%^&*()|~=`{}\\[\\]:\";'<>?]";
var notS = "[^\/\\\\!$%^&*()|~=`{}\\[\\]:\";'<>?]";
var r=new RegExp("^("+notD+notS+"+"+notD+"|"+notD+"{1,2})$");

function match(str) {
	return !! str.match(r);
}


var test = QUnit.test;

test("first test", function(assert) {
  assert.equal(match('abc.com'), true, "abc.com");
  assert.equal(match('a'), true, "a");
  assert.equal(match('abc.c'), true, "abc.c");
  assert.equal(match('abc.'), false, "abc.");
  assert.equal(match('.abc'), false, ".abc");
  assert.equal(match('abc'), true, "abc");
  assert.equal(match('.a.'), false, ".a.");
  
});