3 JavaScript Regular Expression for Malaysia Data Format
Question
Can you share with us the proper Regular Expression (RegExp) for Malaysia’s data format as the following:
- Identification Card
- Postcode
- Phone Number
Answer
Here the answer for above question.
a. Identification Card
/^\d{6}-?\d{2}-?\d{4}$/ allow us to detect Malaysian Identification Card data entry with and without the hyphen (”-”), e.g:
var ic = ["830214-14-5065", "830214145065", "8302-14-5065"]; for(var i = 0; i < ic.length; i++) { if(ic[i].match(/^\d{6}-?\d{2}-?\d{4}$/)) { alert(ic[i] + ": is correct"); } else { alert(ic[i] + ": is false"); } }
b. Postcode
/^\d{5}$/ is a simple RegExp to detect exactly 5-digit numberic value, e.g:
var postcode = ["83040", "8304", "-5065"]; for(var i = 0; i < postcode.length; i++) { if(postcode[i].match(/^\d{5}$/)) { alert(postcode[i] + ": is correct"); } else { alert(postcode[i] + ": is false"); } }
c. Phone Number
/^(\+6)?\d{2,3}-?\d{6,8}$/ allow us to detect fix-line and also mobile number under Malaysian Telco, e.g:
var phone = ["+6012-3456789", "012-3456789", "034567890", "0123456789"]; for(var i = 0; i < phone.length; i++) { if(phone[i].match(/^(\+6)?\d{2,3}-?\d{6,8}$/)) { alert(phone[i] + ": is correct"); } else { alert(phone[i] + ": is false"); } }
Hi, I found your blog on this new directory of WordPress Blogs at blackhatbootcamp.com/listofwordpressblogs. I dont know how your blog came up, must have been a typo, i duno. Anyways, I just clicked it and here I am. Your blog looks good. Have a nice day. James.
hey i wanna ask sumthing…
how can i trace people by using her i/c num and her full name…
but i don’t how how to trace her?even her number…
Can you elaborate on how to trace her?.. What do you mean by actually tracing here.