Permalink
Browse files

Implemented 3 custom constraints from jquery validation: letterswithb…

…asicpunc, lettersonly and alphanumeric
  • Loading branch information...
1 parent 79ffcd6 commit 529eea4102b2d7a758e5c89ab434e3041fc701c9 @limcheekin committed Feb 10, 2011
View
@@ -6,14 +6,20 @@
</projects>
<buildSpec>
<buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
- <nature>com.springsource.sts.grails.core.nature</nature>
+ <nature>com.springsource.sts.grails.core.nature</nature>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
@@ -21,7 +21,7 @@
*/
class JqueryValidationUiGrailsPlugin {
// the plugin version
- def version = "1.1.1"
+ def version = "1.2"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.2.2 > *"
// the other plugins this plugin depends on
@@ -0,0 +1,32 @@
+/* Copyright 2010 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.grails.jquery.validation.ui
+
+/**
+*
+* @author <a href='mailto:limcheekin@vobject.com'>Lim Chee Kin</a>
+*
+* @since 1.2
+*/
+class AlphanumericConstraint {
+
+ def supports = { type ->
+ return type!= null && String.class.isAssignableFrom(type);
+ }
+
+ def validate = { propertyValue ->
+ return propertyValue ==~ /^\w+$/
+ }
+}
@@ -0,0 +1,32 @@
+/* Copyright 2010 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.grails.jquery.validation.ui
+
+/**
+*
+* @author <a href='mailto:limcheekin@vobject.com'>Lim Chee Kin</a>
+*
+* @since 1.2
+*/
+class LettersonlyConstraint {
+
+ def supports = { type ->
+ return type!= null && String.class.isAssignableFrom(type);
+ }
+
+ def validate = { propertyValue ->
+ return propertyValue ==~ /^[a-z]+$/
+ }
+}
@@ -0,0 +1,32 @@
+/* Copyright 2010 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.grails.jquery.validation.ui
+
+/**
+*
+* @author <a href='mailto:limcheekin@vobject.com'>Lim Chee Kin</a>
+*
+* @since 1.2
+*/
+class LetterswithbasicpuncConstraint {
+
+ def supports = { type ->
+ return type!= null && String.class.isAssignableFrom(type);
+ }
+
+ def validate = { propertyValue ->
+ return propertyValue ==~ /^[a-z-.,()'\"\s]+$/
+ }
+}
@@ -0,0 +1,44 @@
+/* Copyright 2010 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.grails.jquery.validation.ui
+
+import grails.test.*
+
+/**
+*
+* @author <a href='mailto:limcheekin@vobject.com'>Lim Chee Kin</a>
+*
+* @since 1.2
+*/
+class AlphanumericConstraintTests extends GroovyTestCase {
+ void testValidAlphanumeric() {
+ def v = new AlphanumericConstraint()
+ v.metaClass.getParams = {-> true }
+
+ assert v.validate("1212LimCheeKin")
+ assert v.validate("1212")
+ assert v.validate("LimCheeKin")
+ }
+
+ void testInvalidAlphanumeric() {
+ def v = new AlphanumericConstraint()
+ v.metaClass.getParams = {-> true }
+
+ assert ! v.validate("1212 LimCheeKin")
+ assert ! v.validate("1 2 1 2")
+ assert ! v.validate("Lim Chee Kin")
+ assert ! v.validate(" ")
+ }
+}
@@ -0,0 +1,44 @@
+/* Copyright 2010 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.grails.jquery.validation.ui
+
+import grails.test.*
+
+/**
+*
+* @author <a href='mailto:limcheekin@vobject.com'>Lim Chee Kin</a>
+*
+* @since 1.2
+*/
+class LettersonlyConstraintTests extends GroovyTestCase {
+ void testValidLettersonly() {
+ def v = new LettersonlyConstraint()
+ v.metaClass.getParams = {-> true }
+
+ assert v.validate("limcheekin")
+ assert v.validate("abc")
+ assert v.validate("cbajdjelaj")
+ }
+
+ void testInvalidLettersonly() {
+ def v = new LettersonlyConstraint()
+ v.metaClass.getParams = {-> true }
+
+ assert ! v.validate("1212 LimCheeKin")
+ assert ! v.validate("1 2 1 2")
+ assert ! v.validate("Lim Chee Kin")
+ assert ! v.validate(" ")
+ }
+}
@@ -0,0 +1,46 @@
+/* Copyright 2010 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.grails.jquery.validation.ui
+
+import grails.test.*
+
+/**
+*
+* @author <a href='mailto:limcheekin@vobject.com'>Lim Chee Kin</a>
+*
+* @since 1.2
+*/
+class LetterswithbasicpuncConstraintTests extends GroovyTestCase {
+ void testValidLetterswithbasicpunc() {
+ def v = new LetterswithbasicpuncConstraint()
+ v.metaClass.getParams = {-> true }
+
+ assert v.validate("limcheekin")
+ assert v.validate("lim, chee kin")
+ assert v.validate("lim-chee-kin")
+ assert v.validate(" ")
+ }
+
+ void testInvalidLetterswithbasicpunc() {
+ def v = new LetterswithbasicpuncConstraint()
+ v.metaClass.getParams = {-> true }
+
+ assert ! v.validate("LimCheeKin")
+ assert ! v.validate("ABC1123")
+ assert ! v.validate("1 2 3 4")
+ assert ! v.validate("222-333-444")
+ }
+
+}

0 comments on commit 529eea4

Please sign in to comment.