Number-field validation

13 years 1 month ago #158292 by jazzstudio
Number-field validation was created by jazzstudio
Hi,

I've posted before, about a year ago, and recieved some advice from folks, but till today I'm still having a hard time getting this to work.

One of the fields in my CB registration is a number-field. It is for a currency amount. The client would like it to function like a normal bank-teller/ATM would:

If I start typing the amount of 42,365.12 and I type the 4, it should show up as 0.04, then I type the 2:
0.42
then 3: 4.23
then 6: 42.36
then 5: 423.65
then 1: 4,236.51
and finally the 2: 42,365.12

Even if this is not exactly possible as presented here, the "second prize" solution would be that if the user types in 42365 that it is accepted as 42,365.00 and indicated as such in that field upon registration as well as for future display.

If the client "adds" the dot, ie: 42365.12, that it shows as 42,365.12

I realize that this may be outside the scope of the CB support, but not sure? I've tried MANY, MANY expressions and none seem to work correctly. Beside that, it appears that for some reason some of the / are simply "dropped" after saving. When I return (after a save) to edit the expressions, then some of the / are missing, and I have to add them again.

Also, since this number field validation simply doesn't seem to work correctly, many of the people attempting to register are having a problem:

There are three different type of registrations: mobilizer, project and resource.

On the drop-down menu in Joomla, I have these three links/options, and each opens a slightly different registration form (I use a plugin that allows multiple registration forms). Obviously, once the user has clicked on (eg) "MOBILIZER" as his choice of registration, we do not want redundant info, thus we do not provide the option of "clicking" or selecting one of the three again. I simply have a hidden field, that receives its info based on the menu-choice the user made. Thus, if they chose MOBILIZER, then the field is auto-filled "mobilizer", and this is used to categorize the users.

Now, since the number validation is causing hassles, often the user types the value, and when it is incorrect, they receive our message about which format the numbers "should" be in, and then get taken back to the registration form. It appears that ALL USERS who experience this issue, are NOT categorized. IE: their hidden field is now NOT being filled. I'm assuming this has something to do with the redirection after the error message.

Ok, so these are two separate issues. I realize this. Yet, they relate to each other closely. Could anyone assist in finding a solution?

Thanks all

Please Log in to join the conversation.

13 years 1 month ago #158346 by krileon
Replied by krileon on topic Re: Number-field validation
I recommend using professional subscriber incubator project CB Queries. What you'd do is after register and after profile update you'd run a query to update _comprofiler. In this query you'd format the value to currency. The below query is what you'd need.
UPDATE `#__comprofiler` SET `MY_FIELD` = FROMAT( `MY_FIELD`, 2 ) WHERE `id` = [user_id]

This would format it from a flat value to currency. If you're wanting validation for currency format then that is a big trickier and you can try using the below REGEX with validation set to custom perl expression.
^[+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?$

The above will validate any combination of US based currency with cents optional.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.190 seconds

Facebook Twitter LinkedIn