Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Text Format

$
0
0

Hi, I have a form on my app that I am trying to setup with a feature that formats text the way its required when i receive the email. The following code works great on iPhone but it freezes up on Android once I enter the first number. Can someone please help me set this up so that it works for both iPhone and Android. Thanks.

I have a file called global.js where I have the code that forces the format. This is what I am using:

Mask = 
{
    mask: function(_field, _function) {
        _field.value = _function(_field.value);
    },
 
    dob: function(v) {
        v = v.replace(/\D/g,"");
        v = v.replace(/^(\d\d)(\d)/g,"$1/$2");
        v = v.replace(/(\d{2})(\d)/,"$1/$2");
        return v.slice(0, 10);
    },
 
    phone: function(v) {
        v = v.replace(/\D/g,"");
        v = v.replace(/^(\d\d)(\d)/g,"($1) $2");
        v = v.replace(/(\d{4})(\d)/,"$1-$2");
        return v.slice(0, 14);
    }
};
On my form i added the following on the top of the of the view for the global.js:
var styles = require('global').Styles;
Then my field is as follows:
// Create a TextField.
    var aTextField_dob = Ti.UI.createTextField({
        top : "10%",
        width : '80%',
        height:'8%',
        color: styles.textfield.color,
        font : {
            fontSize : font_text
        },
        hintText : 'Date of Birth (Ex.01/01/1999)',
        paddingLeft : styles.textfield.paddingLeft,
        backgroundImage : styles.textfielda.backgroundImage,
    });
 
    // Listen for return events.
    aTextField_dob.addEventListener('change', function(e) {
        Mask.mask(aTextField_dob, Mask.dob);
    });

Thanks for your help guys.


Viewing all articles
Browse latest Browse all 8068

Trending Articles