Pages

December 26, 2014

Collapse pageBlockSection on page load

Hi Friends,

It is very often situation where we want to collapse a section on visualforce page while loading the page to hide some part/information on page. It is very easy in visualforce by using a line of javascript code. Use below code and that's it, you are done.

<apex:pageBlockSection title=" Section Title " id="section1">

<Script> twistSection(document.getElementById("{!$Component.section1}").childNodes[0].childNodes[0]);

</script>

</apex:pageBlockSection>


Thanks

May 31, 2013

Email and Mobile number validation in Swing

Now validation of Email address and Mobile Number in Java Swing is very easy.
In Swing we take input from user in textfields, and to validate that input such as email and Mobile number  
here is the small code:

let say your textfield name for Email and Mobile number field is "txtEmail" and "txtMobile" then

String email = txtEmail.getText();
String mobNumber = txtMobile.getText();
boolean testEmail, testMob;
Pattern patternEmail, patternMob;
Matcher matcherEmail, matcherMob;
private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
    + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private static final String MOBILE_PATTERN = "\\d{10}";

patternEmail = Pattern.compile(EMAIL_PATTERN);
matcherEmail = patternEmail.matcher(email);
testEmail = return matcherEmail.matches();
patternMob = Pattern.compile(MOBILE_PATTERN);
matcherMob = patternMob.matcher(mobNumber);
testMob = return matcherMob.matches();

now based on the value of testEmail and testMob, you can display an error message to user using

JOptionPane.showMessageDialog(null, "Enter Email in correct format");

Hope this code is useful to you.

Thanks.