Run Regex on Mobile number input

Hey,

is there a way to run regex code when a user types in his/her mobile number? We coded a basic mobile phone validator and would like to use it :wink:

kind regards

The input field already validates US phone numbers. Are you trying to do something outside of that?

image

Twilio lookup does this. Very easy API to connect and free to use as a formatter. Works well with @gaurav’s new phone input plugin.

If you want MORE info about a phone number (validate carrier, identify mobile, etc. it’s half a cent for carrier info and I think one sent for validation).

(Sorry, I’m mobile. Just google Twilio Lookup API for all the deets. I’m impressed with this one.)

Edit - more: Twilio Lookup at the free level is essentially the formatting/validation functions of Google’s libphonenumber library, which is not easy to implement in Bubble. So a free, super fast API version of that is perfect for use with Bubble. Wish there were more things like this.

One caveat: IF the number is not valid for the country code in question (or its not a phone number, like the string “not my phone number”),it returns error code 202404 or something like that. You just handle that using Bubble’s primitive error handling and that’s how you know the number is not valid. It would be better if it returned something in the JSON response, but you know it’s free. And this is not a significant issue. It’s just if I were building that API, I’d return 200 success and have a flag like “valid” in the response, set to “no”. But folks don’t design their APIs for Bubble, right?)

Hi,

What exactly are you trying to validate?
The ‘better phone input’ plugin auto validates every number and output’s is valid number (yes/no) as one of it’s values. It also outputs whether the number is mobile, fixed line, fax etc.

Link to the plugin in this thread: Bubble Developer Kit

Thanks!

Thanks for your response!
Im located in Germany, so US Phone does not work here…

Thanks for your response!

It seems like a great Plug In but we are looking for something thats free. This is why we coded the Regular Expression. :slight_smile:

1 Like

In answer to your original question, yes, you can do regex operations on text objects. Text objects have several operators that can be used with RegEx. These are described in the Reference, but not extensively documented though the interfaces are pretty clear:

Both find/replace and extract with RegEx can accept regex. (There may be other text operators that also accept regex as an option, but I don’t think so…)

From the reference:


:find/replace…

Dynamically defines text to use in find and replace. It returns a new text. The find and replace happens for the entire text.

:extract with Regex

This is an advanced feature that extracts entries from a text using a regex. For example, if the regex is ‘@\S+’ and the text is ‘@one_name and @another_name,’ this returns a list of texts: @one_name, @another_name.


Twilio has a good brief article on E.164 format phone numbers and a RegEx for matching that standard. As they note, “validating” an E.164 value in this way will also match numbers that are not valid phone numbers.

They go on to recommend using their Lookup API (of course).

Other solutions include @gaurav’s pretty-darn-good implementation of intl-tel-input.js, working up your own plug-in or in-page implementation of intl-tel-input.js, implementing Google’s libphonenumber library (which is in part what intl-tel-input does). BTW libphonenumber seems to be quite complex to implement in general and would likely be a real pain to implement in a Bubble site.

Phone number validation is one of those things that is just not simple.

What I’m doing in my main app is using @gaurav’s plug in as an entry field (this gives you an E.164 format phone number that is “validated” to the extent that libphonenumber can “validate” a phone number). I use free call to Twilio Lookup to return the E.164 phone number in the country’s local format. And I shove all of the data into a data type that has all of the info gathered so that I have a great deal of flexibility in using and formatting those numbers.

The OP here is in Germany so wants to be able to validate and format what we would call “international” phone numbers.

My own experience: I thought before launching GRUPZ as a live app that my customer base would be highly US-centric. I could not have been more wrong. My paying customers (and the properties they use the GRUPZ tools for) are everywhere in the world.

And so it turns out that Bubble’s phone number facilities at present are woefully inadequate. And the more I investigated the general issue of phone number UIs and how one should store phone numbers in one’s database, the worse Bubble looks.

Except for quick and dirty mockups, I will no longer rely on the default Bubble phone input interface (which is only good for US) and also have taken to storing phone numbers and meta-data about those numbers as a complex data type like this:

This opens the door to extending that data type even further if I choose to offer more in-depth phone validation or phone number authentication in the future (either of those would probably be value-add microtransactions in my service).

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.