Implement serverside and client side validatation

This commit is contained in:
YNH Webdev
2013-09-06 18:06:43 +02:00
parent 9f40c6355c
commit bbd48d24e4
19 changed files with 492 additions and 84 deletions

View File

@@ -18,7 +18,7 @@ feature {NONE}
make_decimal_validator (e: STRING)
do
make_regexp_validator ("[0-9]+(\\.[0-9]*)?|\\.[0-9]+", e)
make_regexp_validator ("^[0-9]+(\.[0-9]*)?$|^\.[0-9]+$", e)
end
end

View File

@@ -14,7 +14,7 @@ inherit
create
make_email_validator
feature{NONE}
feature {NONE}
make_email_validator (e: STRING)
do

View File

@@ -10,6 +10,9 @@ class
inherit
WSF_VALIDATOR [STRING]
redefine
state
end
create
make_regexp_validator
@@ -18,21 +21,32 @@ feature {NONE}
make_regexp_validator (r, e: STRING)
do
make(e)
make (e)
regexp_string := r
create regexp
regexp.compile (r)
end
feature -- Implementation
validate (input: STRING): BOOLEAN
is_valid (input: STRING): BOOLEAN
do
--Only compile when used
if not regexp.is_compiled then
regexp.compile (regexp_string)
end
Result := regexp.matches (input)
end
feature
state: JSON_OBJECT
do
create Result.make
Result.put (create {JSON_STRING}.make_json ("WSF_REGEXP_VALIDATOR"), create {JSON_STRING}.make_json ("name"))
Result.put (create {JSON_STRING}.make_json (regexp_string), create {JSON_STRING}.make_json ("expression"))
Result.put (create {JSON_STRING}.make_json (error), create {JSON_STRING}.make_json ("error"))
end
regexp_string: STRING
regexp: REGULAR_EXPRESSION

View File

@@ -0,0 +1,20 @@
note
description: "Summary description for {WSF_VALIDATABLE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_VALIDATABLE
feature
validate
deferred
end
is_valid: BOOLEAN
deferred
end
end

View File

@@ -16,7 +16,14 @@ feature {NONE}
feature
validate (input: G): BOOLEAN
state: JSON_OBJECT
do
create Result.make
Result.put (create {JSON_STRING}.make_json (generator), create {JSON_STRING}.make_json ("name"))
Result.put (create {JSON_STRING}.make_json (error), create {JSON_STRING}.make_json ("error"))
end
is_valid (input: G): BOOLEAN
deferred
end