Your Existence Your Existence

Proofreeded buy Proofreeded buy Jamon Holmgren Jamon Holmgren

Who am I? Who am I?

@GantLaborde @GantLaborde Public Spe ak er Writ er Coder

Title Text Title Text

Trusting User Input Trusting User Input

Crazy or Lazy? Crazy or Lazy?

Start with ideal API Start with ideal API

Have smart people Have smart people help! help!

Ideal Validation? Ideal Validation?

We can validate information

valid?(

98.6 , : number )

#=> true

Get user input T HEN v alidat e it in some place.

Stop them at the Stop them at the Source Source

Ideal Validation? Ideal Validation? t ak e 2

We can validate user input at the source

@username_textfield.validates(

:number ).on( :invalid ) do

Alert the user!

end

Validation as a Utility Validation as a Utility 1/5

H a n d l e

c o m m o n

v a l i d a t i o n

n e e d s

r m q . v a l i d a t i o n . v a l i d ? ( ' t e s t @ t e s t . c o m ' ,

: e m a i l )

r e t u r n s

t r u e

r m q . v a l i d a t i o n . v a l i d ? ( ' 5 0 4 5 5 5 8 9 8 9 ' ,

: u s p h o n e )

r e t u r n s

t r u e

r m q . v a l i d a t i o n . v a l i d ? ( ' 9 0 2 1 0 ' ,

: u s z i p )

r e t u r n s

f a l s e

Validation as a Utility Validation as a Utility 2/5   :email   :url   :dat eiso   :number :digits   :ip v4 :time     :uszip :ukzip :usphone   :str ong_p assw or d :has_upper   :has_l o w er   :pr esenc e :l ength  

Validation as a Utility Validation as a Utility 3/5 # Make

it

Flexable

rmq .validation .valid ?( 'test' , :length, exact_length : 4 ) #true

rmq .validation .valid ?( 'test' , :length, min_length : 4 ) #true

rmq .validation .valid ?( 'test' , :length, max_length : 4 ) #true

rmq .validation .valid ?( 'test' , :length, min_length : 2 , max_length : 7 ) #true

rmq .validation .valid ?( 'test' , :length, exact_length : 2 .. 7 ) #true

rmq .validation .valid ?( ' test ' , :length, max_length : 5 , strip : true) #true

Validation as a Utility Validation as a Utility 4/5

R o l l

y o u r

o w n !

r m q . v a l i d a t i o n . v a l i d ? ( ' n a c h o ' ,

: c u s t o m ,

r e g e x :

R e g e x p . n e w ( ' n a c h o s ? ' ) )

t r u e

Things that validation has to think about? Things that validation has to think about? allow_blank white_list Validation as a Utility Validation as a Utility 5/5

Friday Friday

Validation as a Rule Validation as a Rule Built on the Utility

Validation as a Rule Validation as a Rule  

A d d

a

r u l e

t o

a

t e x t f i e l d

r m q ( @ u s e r _ e m a i l ) . v a l i d a t e s ( : e m a i l )

A d d

r u l e

a s s

w e

a p p e n d

f i e l d s

r m q . a p p e n d ( U I T e x t F i e l d ,

: w e i g h t ) . v a l i d a t e s ( : d i g i t s )

r m q . a p p e n d ( U I T e x t F i e l d ,

: n a m e ) . v a l i d a t e s ( : p r e s e n c e )

C h e c k

t h a t

i n p u t

r m q ( @ u s e r _ e m a i l ) . v a l i d ?

C h e c k

e v e r y

a p p l i e d

r u l e

r m q . a l l . v a l i d ?

Who's Bad? Who's Bad?

Useless at first

rmq(some_selection_criteria).invalid 

rmq(some_selection_criteria).valid

moment of judgement

rmq.all.valid?

All invalid views as an array

rmq.all.invalid 

All valid views as an array

rmq.all.valid

Who's Bad? Who's Bad?

I react depending on my own state

rmq.append(UITextField).validates( :digits ).on( :valid ) do

#valid

puts "WOWZERZ field is valid <3 <3 <3"

end .on( :invalid ) do

|invalid|

#invalid

puts "NOOOOOOOOOOOOO!!!1!1"

end

Easy Come - Easy Go Easy Come - Easy Go

Bye bye Guy

rmq(some_selection).clear_validations!

Later alligator

rmq.all.clear_validations!

Informative Errors Informative Errors

We can be friendly We can be friendly validation_errors

R e t u r n s

a r r a y

o f

e r r o r

m e s s a g e s

f o r

e v e r y

i n v a l i d

i t e m

i n

s e l e c t i o n

r m q . a l l . v a l i d a t i o n _ e r r o r s

E . G

[ " V a l i d a t i o n

E r r o r

i n p u t

r e q u i r e s

v a l i d

e m a i l . " ]

We can be friendly We can be friendly custom error messages custom error messages

d o

t h i s

i n

y o u r

s t y l e s h e e t

d e f

u s e r ( s t )

c u s t o m

v a l i d a t i o n

i m a g e s

s t . v a l i d a t i o n _ e r r o r s

=

{

e m a i l :

" P l e a s e

c h e c k

y o u r

u s e r

e m a i l

a n d

t r y

a g a i n "

}

e n d

o v e r r i d e s

" V a l i d a t i o n

E r r o r

i n p u t

r e q u i r e s

v a l i d

e m a i l . "

Custom Validations Custom Validations with Selection Rules!?! with Selection Rules!?! Custom Validations Custom Validations with Selection Rules!?! with Selection Rules!?!

Custom Validation Custom Validation Rules Rules   the e asy w ay - simple r egex

a p p e n d ( U I T e x t F i e l d ) . v a l i d a t e s ( : c u s t o m ,

r e g e x :

/ ^ t e s t $ / )

Custom Validation Custom Validation Rules Rules

r m q . v a l i d a t i o n . a d d _ v a l i d a t o r ( : f i r s t _ l e t t e r )

d o

| v a l u e ,

o p t s |

v a l u e . s t a r t _ w i t h ? ( o p t s [ : l e t t e r ] )

e n d No w use it!

s o m e _ f i e l d

=

a p p e n d ( U I T e x t F i e l d ) . v a l i d a t e s ( : f i r s t _ l e t t e r ,

l e t t e r :

' x ' )

s o m e _ f i e l d . d a t a ( " t e s t " )

s o m e _ f i e l d . v a l i d ?

=

f a l s e

s o m e _ f i e l d . d a t a ( " x e n o p h o b i a " )

s o m e _ f i e l d . v a l i d ?

=

t r u e

Mark Rick ert (aka the "Bad Bo y of Rub yMotion" )

Hangin' with BroBama Hangin' with BroBama

The Future of The Future of Validation Validation

Thanks! Thanks! Thanks! Thanks!