Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an input box which asks users to input a UK postcode but which specifies that this must be in lower case, for example so16 0as. Some users find this frustrating as they would just like to copy and paste a post code into the textfield; the copied postcode may contain upper case letters ie SO16 0AS. This will return an error.

The input code is as follows:

items: [{
            xtype: "textfield",
            width: 220,
            name: "search_lc",
            value: "",
            emptyText:'Enter Postcode (e.g. so16 0as)',
            fieldLabel: "Find",
            allowblank: false
        }],

I have tried to use fieldStyle: 'text-transform:lowercase' both below the fieldLabel and above it but this doesn't work.

I'mm thinking that this should be a fairly simple thing to resolve but I am experiencing a 'can't see the wood for the trees moment'! Any help gratefully received!

Many thanks,

Red.

share|improve this question
add comment

1 Answer

Use a custom validation function, see the API of Ext (GeoExt base for non-Geo stuff) for that: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Text-cfg-validator .

Even better: use a Regular Expression, as

items: [{
    xtype: 'textfield',
    name: 'name',
    fieldLabel: 'Name',
    allowBlank: false,  // requires a non-empty value
    regex: /^[A-Za-z0-9]+$/
}

I am unfamiliar with the exact Regex needed for validating a UK postcode, so i allow all letters and numbers. Google tells me it is a bit more complex, see for example regexlib.com/REDetails.aspx?regexp_id=260 .

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.