Skip to content

Commit

Permalink
Add rule.js => angular-validation-rule.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hueitan committed Jul 3, 2014
1 parent 2b1e06e commit 6a682b0
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 61 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ grunt dev

**Start coding**
```
open `provider.js`, looking for `var expression` and `var defaultMsg`
open `rule.js`, looking for `var expression` and `var defaultMsg`
Adding a new expression and defaultMsg to extend it
```

Expand Down
6 changes: 4 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ module.exports = function (grunt) {
concat: {
basic_and_extras: {
files: {
'dist/angular-validation.js': ['src/module.js', 'src/provider.js', 'src/directive.js']
'dist/angular-validation.js': ['src/module.js', 'src/provider.js', 'src/directive.js'],
'dist/angular-validation-rule.js': ['src/rule.js']
}
}
},
uglify: {
my_target: {
files: {
'dist/angular-validation.min.js': ['dist/angular-validation.js']
'dist/angular-validation.min.js': ['dist/angular-validation.js'],
'dist/angular-validation-rule.min.js': ['dist/angular-validation-rule.js']
}
}
},
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ npm install angular-validation

Using angular-validation
---
```javascript
```html
<script src="dist/angular-validation.js"></script>
<script src="dist/angular-validation-rule.js"></script>
```
```js
angular.module('yourApp', ['validation']);

// including your validation rule
angular.module('yourApp', ['validation', 'validation.rule']);
```

Writing your Code
Expand Down Expand Up @@ -278,7 +285,7 @@ Easily disable success/error message
}]);
```

Built-in validation <small>in angular-validation</small>
Built-in validation <small>in angular-validation-rule</small>
===

1. Required
Expand Down
1 change: 1 addition & 0 deletions config/karma.conf.angular.1.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function(config) {
'test/lib/angular.1.2.16.js',
'test/lib/angular-mocks.1.2.16.js',
'dist/angular-validation.js',
'dist/angular-validation-rule.js',
'test/unit/*.js'
],

Expand Down
1 change: 1 addition & 0 deletions config/karma.conf.angular.1.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function(config) {
'test/lib/angular.1.3.0-beta.5.js',
'test/lib/angular-mocks.1.3.0-beta.5.js',
'dist/angular-validation.js',
'dist/angular-validation-rule.js',
'test/unit/*.js'
],

Expand Down
2 changes: 1 addition & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function () {
angular.module('myApp', ['validation'])
angular.module('myApp', ['validation', 'validation.rule'])

// -------------------
// config phase
Expand Down
35 changes: 35 additions & 0 deletions dist/angular-validation-rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function () {
angular.module('validation.rule', ['validation'])
.config(['$validationProvider', function ($validationProvider) {

var expression = {
required: /^.+$/,
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
email: /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,
number: /^\d+$/
};

var defaultMsg = {
required: {
error: 'This should be Required!!',
success: 'It\'s Required'
},
url: {
error: 'This should be Url',
success: 'It\'s Url'
},
email: {
error: 'This should be Email',
success: 'It\'s Email'
},
number: {
error: 'This should be Number',
success: 'It\'s Number'
}
};

$validationProvider.setExpression(expression).setDefaultMsg(defaultMsg);

}]);

}).call(this);
1 change: 1 addition & 0 deletions dist/angular-validation-rule.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 4 additions & 26 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,16 @@

/**
* Define validation type RegExp
* @type {{required: RegExp, url: RegExp, email: RegExp}}
* @type {{}}
*/
var expression = {
required: /^.+$/,
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
email: /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,
number: /^\d+$/
};
var expression = {};


/**
* default error, success message
* @type {{required: {error: string, success: string}, url: {error: string, success: string}, email: {error: string, success: string}, number: {error: string, success: string}}}
* @type {{}}
*/
var defaultMsg = {
required: {
error: 'This should be Required!!',
success: 'It\'s Required'
},
url: {
error: 'This should be Url',
success: 'It\'s Url'
},
email: {
error: 'This should be Email',
success: 'It\'s Email'
},
number: {
error: 'This should be Number',
success: 'It\'s Number'
}
};
var defaultMsg = {};


/**
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ <h1>Angular Validation.
<a href="https://github.com/huei90/angular-validation"><img src="demo/iconmonstr-github-10-icon-128.png" id="github-link" alt="Fork me on Github"/></a>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="dist/angular-validation.js"></script>
<script src="dist/angular-validation-rule.js"></script>
<script src="demo/demo.js"></script>

</body>
Expand Down
30 changes: 4 additions & 26 deletions src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,16 @@

/**
* Define validation type RegExp
* @type {{required: RegExp, url: RegExp, email: RegExp}}
* @type {{}}
*/
var expression = {
required: /^.+$/,
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
email: /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,
number: /^\d+$/
};
var expression = {};


/**
* default error, success message
* @type {{required: {error: string, success: string}, url: {error: string, success: string}, email: {error: string, success: string}, number: {error: string, success: string}}}
* @type {{}}
*/
var defaultMsg = {
required: {
error: 'This should be Required!!',
success: 'It\'s Required'
},
url: {
error: 'This should be Url',
success: 'It\'s Url'
},
email: {
error: 'This should be Email',
success: 'It\'s Email'
},
number: {
error: 'This should be Number',
success: 'It\'s Number'
}
};
var defaultMsg = {};


/**
Expand Down
35 changes: 35 additions & 0 deletions src/rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function () {
angular.module('validation.rule', ['validation'])
.config(['$validationProvider', function ($validationProvider) {

var expression = {
required: /^.+$/,
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
email: /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,
number: /^\d+$/
};

var defaultMsg = {
required: {
error: 'This should be Required!!',
success: 'It\'s Required'
},
url: {
error: 'This should be Url',
success: 'It\'s Url'
},
email: {
error: 'This should be Email',
success: 'It\'s Email'
},
number: {
error: 'This should be Number',
success: 'It\'s Number'
}
};

$validationProvider.setExpression(expression).setDefaultMsg(defaultMsg);

}]);

}).call(this);
3 changes: 2 additions & 1 deletion test/unit/directivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('directives', function () {
element;

beforeEach(module('validation.directive'));

beforeEach(module('validation.rule'));

describe('Example of Required', function () {

beforeEach(inject(function ($injector) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/providerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('provider', function () {
myApp;

beforeEach(function () {
myApp = angular.module('myApp', ['validation'])
myApp = angular.module('myApp', ['validation', 'validation.rule'])
.config(function ($validationProvider) {
validationProvider = $validationProvider;
});
Expand Down

0 comments on commit 6a682b0

Please sign in to comment.