Not used the validates_as_phone plugin before, but looking at the
source for validates_as_phone, it is only allowing lengths of 7, 10
and 11 for the string length.
You could either ‘monkey patch’ the plugin to do what you want (e.g.
accept string length of 0), or use the plugin’s code as a base for
writing your own validation plugin.
Rails 2 also has an allow_blank property for validations but i’m not
sure if this would be supported by this custom plugin. I can’t see
anywhere in the code where it would check this explicitly but you
could try this if you are on v2. allow_nil will only validate if the
actual value from the parameters hash is nil, not if it is “”
The plugin doesn’t really look too amazing, to be honest, It only
strips out any non-numeric characters and checks for length. Sure that
US phone numbers are more complex than that! It is also not very
optimised, calling the same methods several times (namely
new_value.length) instead of storing this computation in a variable.