Skip to content

Instantly share code, notes, and snippets.

@bootcoder
Created September 15, 2016 17:34
Show Gist options
  • Save bootcoder/f014bb6504c86d2a43ad39d8d49027e0 to your computer and use it in GitHub Desktop.
Save bootcoder/f014bb6504c86d2a43ad39d8d49027e0 to your computer and use it in GitHub Desktop.
notes
phone numbers -- format?
string == 3525678908
string == (352)5678908
string == (352)567-8908
string == 352.567.8908
string == 3525678908
error handling
areacode 352
prefix 870
suffic 6756
<form>
<input type="text" name="user[phone][areacode]">
<input type="text" name="user[phone][prefix]">
<input type="text" name="user[phone][suffix]">
</form>
<form>
<input type="text" name="user[phone]">
</form>
MODEL
def sanitize_phone_input(input)
<!-- use regex here to remove all chacters which are not digits -->
self.phone_numebr = reged_input
end
post '/users' do
end
MODEL before validates run callback concat phone to make a single string from the 3 inputs
then run a model validation to check the format of said string (10 digits also only digits)
additionally though I would set up some javascript to validate the input on the frontend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment