Skip to content

Commit

Permalink
Use \A and \z in regexp for stricter matching
Browse files Browse the repository at this point in the history
* While \A and ^ are the same, there is a difference between \z and $

  Using $ it will match the "end of line", which means that this would
  match strings like: "en-US\n". While \z means "end of string" and it
  will not match that, and will only match "en-US".

  I would assert that most of the time when using anchors you would want
  to use \A and \z, only falling back to ^ and $ in specific cases.
  • Loading branch information
dkubb committed Jun 9, 2010
1 parent 6808c3e commit 09efcc2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/common/language.rb
Expand Up @@ -10,7 +10,7 @@ class Language
property :name, String, :required => true

# locale string like 'en-US'
validates_format_of :code, :with => /^[a-z]{2}-[A-Z]{2}$/
validates_format_of :code, :with => /\A[a-z]{2}-[A-Z]{2}\z/


def self.[](code)
Expand Down

0 comments on commit 09efcc2

Please sign in to comment.