Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General solution to phone number format #1462

Open
biwashingtonial opened this issue Jun 16, 2015 · 5 comments
Open

General solution to phone number format #1462

biwashingtonial opened this issue Jun 16, 2015 · 5 comments

Comments

@biwashingtonial
Copy link
Contributor

In reference to #597 and #335, how difficult would it be to teach Formageddon to handle phone formatting like this?

      - name: field_62cac646-c6c0-4b48-8637-86b77d2c9700
        selector: "#field_62cac646-c6c0-4b48-8637-86b77d2c9700"
        value: "$PHONE"
        format: "(012) 345-6789"
        required: true

That format value would give the 0th through 9th digits of $PHONE in whatever sequence plus whatever other characters necessary. If omitted, it would default to 012-345-6789. This way $PHONE_PARENTHESES and $PHONE_UNDASHED, etc. aren't necessary, and the YAMLs can also accommodate forms that divide the phone number over multiple fields. (I don't know of any Congressional contact forms doing this yet, but at least one gubernatorial form does.)

Thoughts?

@j-ro
Copy link
Contributor

j-ro commented Jun 16, 2015

I think you'd probably want to use regex, no?

Generally I've been fudging these. Most forms (gov and state level included) will take just digits just fine, which is what we generally send. There are a few that need the parentheses version, so we use that there instead. For forms that split up the fields, we just put the entire number in each one and it works for every that I've encountered. So I'm not feeling any urgency to really fix this :)

@biwashingtonial
Copy link
Contributor Author

Regex is certainly a powerful solution. It would look something like:

      - name: field_62cac646-c6c0-4b48-8637-86b77d2c9700
        selector: "#field_62cac646-c6c0-4b48-8637-86b77d2c9700"
        value: "$PHONE"
        regex_match: "([0-9]{3})([0-9]{3})([0-9]{4})"
        regex_replace: "($1) $2-$3"
        required: true

I was going for user-friendliness on the YAML generation side, but regex would be a cinch to implement, and could apply to any field with a text value. I like it.

@j-ro
Copy link
Contributor

j-ro commented Jun 16, 2015

Yeah, me too -- formatting other fields is a nice bonus.

Now, we'd probably want it in the options hash too, like this extension:

#1454

@biwashingtonial
Copy link
Contributor Author

Sounds good to me. Like so:

      - name: field_62cac646-c6c0-4b48-8637-86b77d2c9700
        selector: "#field_62cac646-c6c0-4b48-8637-86b77d2c9700"
        value: "$PHONE"
        options:
          match: "([0-9]{3})([0-9]{3})([0-9]{4})"
          replace: "($1) $2-$3"
        required: true

@j-ro
Copy link
Contributor

j-ro commented Jun 16, 2015

yep, I like it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants