Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for validating postcode and phone number

I am creating a form, with warning elements. All works great but need to define my patterns better.

                $("#postcode").inputNotes( 
              {
                warning: {
                  pattern: /^[0-9]+$/,
                  type: 'note',
                  text: 'Only numbers, please ...',
                  inversedBehavior: true
                }
              }
            );
            $("#phone").inputNotes( 
              {
                warning: {
                  pattern: /^[0-9]+$/,
                  type: 'note',
                  text: 'Only numbers, no spaces please ...',
                  inversedBehavior: true
                }
              }
            );

Ok for the Postcode warning, I want the pattern to expect 4 numbers

For the Phone warning, I want the pattern to expect 10 numbers.

Any help appreciated.

like image 547
422 Avatar asked Nov 28 '22 07:11

422


1 Answers

Here are the rules for Australian postcodes:

ACT: 0200-0299 and 2600-2639.

NSW: 1000-1999, 2000-2599 and 2640-2914.

NT: 0900-0999 and 0800-0899.

QLD: 9000-9999 and 4000-4999.

SA: 5000-5999.

TAS: 7800-7999 and 7000-7499.

VIC: 8000-8999 and 3000-3999.

WA: 6800-6999 and 6000-6799

Regular Expression: ^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$

Pass: 0200|||7312|||2415

Fail: 0300|||7612|||2915

like image 109
stuartdotnet Avatar answered Dec 06 '22 15:12

stuartdotnet