Skip to content

Commit 529eea4

Browse files
committed
Implemented 3 custom constraints from jquery validation: letterswithbasicpunc, lettersonly and alphanumeric
1 parent 79ffcd6 commit 529eea4

File tree

8 files changed

+238
-2
lines changed

8 files changed

+238
-2
lines changed

.project

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.jdt.core.javabuilder</name>
1015
<arguments>
1116
</arguments>
1217
</buildCommand>
1318
</buildSpec>
1419
<natures>
15-
<nature>com.springsource.sts.grails.core.nature</nature>
20+
<nature>com.springsource.sts.grails.core.nature</nature>
1621
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
1722
<nature>org.eclipse.jdt.core.javanature</nature>
23+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
1824
</natures>
1925
</projectDescription>

JqueryValidationUiGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class JqueryValidationUiGrailsPlugin {
2323
// the plugin version
24-
def version = "1.1.1"
24+
def version = "1.2"
2525
// the version or versions of Grails the plugin is designed for
2626
def grailsVersion = "1.2.2 > *"
2727
// the other plugins this plugin depends on
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Copyright 2010 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.grails.jquery.validation.ui
16+
17+
/**
18+
*
19+
* @author <a href='mailto:[email protected]'>Lim Chee Kin</a>
20+
*
21+
* @since 1.2
22+
*/
23+
class AlphanumericConstraint {
24+
25+
def supports = { type ->
26+
return type!= null && String.class.isAssignableFrom(type);
27+
}
28+
29+
def validate = { propertyValue ->
30+
return propertyValue ==~ /^\w+$/
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Copyright 2010 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.grails.jquery.validation.ui
16+
17+
/**
18+
*
19+
* @author <a href='mailto:[email protected]'>Lim Chee Kin</a>
20+
*
21+
* @since 1.2
22+
*/
23+
class LettersonlyConstraint {
24+
25+
def supports = { type ->
26+
return type!= null && String.class.isAssignableFrom(type);
27+
}
28+
29+
def validate = { propertyValue ->
30+
return propertyValue ==~ /^[a-z]+$/
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Copyright 2010 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.grails.jquery.validation.ui
16+
17+
/**
18+
*
19+
* @author <a href='mailto:[email protected]'>Lim Chee Kin</a>
20+
*
21+
* @since 1.2
22+
*/
23+
class LetterswithbasicpuncConstraint {
24+
25+
def supports = { type ->
26+
return type!= null && String.class.isAssignableFrom(type);
27+
}
28+
29+
def validate = { propertyValue ->
30+
return propertyValue ==~ /^[a-z-.,()'\"\s]+$/
31+
}
32+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright 2010 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.grails.jquery.validation.ui
16+
17+
import grails.test.*
18+
19+
/**
20+
*
21+
* @author <a href='mailto:[email protected]'>Lim Chee Kin</a>
22+
*
23+
* @since 1.2
24+
*/
25+
class AlphanumericConstraintTests extends GroovyTestCase {
26+
void testValidAlphanumeric() {
27+
def v = new AlphanumericConstraint()
28+
v.metaClass.getParams = {-> true }
29+
30+
assert v.validate("1212LimCheeKin")
31+
assert v.validate("1212")
32+
assert v.validate("LimCheeKin")
33+
}
34+
35+
void testInvalidAlphanumeric() {
36+
def v = new AlphanumericConstraint()
37+
v.metaClass.getParams = {-> true }
38+
39+
assert ! v.validate("1212 LimCheeKin")
40+
assert ! v.validate("1 2 1 2")
41+
assert ! v.validate("Lim Chee Kin")
42+
assert ! v.validate(" ")
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright 2010 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.grails.jquery.validation.ui
16+
17+
import grails.test.*
18+
19+
/**
20+
*
21+
* @author <a href='mailto:[email protected]'>Lim Chee Kin</a>
22+
*
23+
* @since 1.2
24+
*/
25+
class LettersonlyConstraintTests extends GroovyTestCase {
26+
void testValidLettersonly() {
27+
def v = new LettersonlyConstraint()
28+
v.metaClass.getParams = {-> true }
29+
30+
assert v.validate("limcheekin")
31+
assert v.validate("abc")
32+
assert v.validate("cbajdjelaj")
33+
}
34+
35+
void testInvalidLettersonly() {
36+
def v = new LettersonlyConstraint()
37+
v.metaClass.getParams = {-> true }
38+
39+
assert ! v.validate("1212 LimCheeKin")
40+
assert ! v.validate("1 2 1 2")
41+
assert ! v.validate("Lim Chee Kin")
42+
assert ! v.validate(" ")
43+
}
44+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Copyright 2010 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.grails.jquery.validation.ui
16+
17+
import grails.test.*
18+
19+
/**
20+
*
21+
* @author <a href='mailto:[email protected]'>Lim Chee Kin</a>
22+
*
23+
* @since 1.2
24+
*/
25+
class LetterswithbasicpuncConstraintTests extends GroovyTestCase {
26+
void testValidLetterswithbasicpunc() {
27+
def v = new LetterswithbasicpuncConstraint()
28+
v.metaClass.getParams = {-> true }
29+
30+
assert v.validate("limcheekin")
31+
assert v.validate("lim, chee kin")
32+
assert v.validate("lim-chee-kin")
33+
assert v.validate(" ")
34+
}
35+
36+
void testInvalidLetterswithbasicpunc() {
37+
def v = new LetterswithbasicpuncConstraint()
38+
v.metaClass.getParams = {-> true }
39+
40+
assert ! v.validate("LimCheeKin")
41+
assert ! v.validate("ABC1123")
42+
assert ! v.validate("1 2 3 4")
43+
assert ! v.validate("222-333-444")
44+
}
45+
46+
}

0 commit comments

Comments
 (0)