Wednesday, May 28, 2014

Get Selected Check box Value and Select all Check boxes using "Select All" option using JavaScript

Html / JSP

  <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnGetSelectedValue').click( function(){
        var chkId = '';
        $('.chkNumber:checked').each(function() {
          chkId += $(this).val() + ",";
        });
        chkId =  chkId.slice(0,-1);
        alert(chkId);
      });

      $('.chkSelectAll').click( function(){

        $('.chkNumber').prop('checked', $(this).is(':checked'));
      });

    });

  </script>

  <div>
    <input type="checkbox" class="chkNumber" value="1" />One<br />
    <input type="checkbox" class="chkNumber" value="2" />Two<br />
    <input type="checkbox" class="chkNumber" value="3" />Three<br />
    <input type="checkbox" class="chkNumber" value="4" />Four<br />
    <input type="checkbox" class="chkNumber" value="5" />Five<br /><br />
  </div>
  <button type="button" class="btnGetSelectedValue">GetSelectedValue</button><br />
  <input type="checkbox" class="chkSelectAll" />SelectAll

get all selected checkbox value

var chkId = '';
$('.chkNumber:checked').each(function() {
  chkId += $(this).val() + ",";
});
chkId = chkId.slice(0,-1);// Remove last comma

Select all CheckBox on single click

$('.chkNumber').prop('checked', true);



Tuesday, May 27, 2014

Windows File Name Validation

public static boolean isValidName(String text)
{
    Pattern pattern = Pattern.compile(
        "# Match a valid Windows filename (unspecified file system).          \n" +
        "^                                # Anchor to start of string.        \n" +
        "(?!                              # Assert filename is not: CON, PRN, \n" +
        "  (?:                            # AUX, NUL, COM1, COM2, COM3, COM4, \n" +
        "    CON|PRN|AUX|NUL|             # COM5, COM6, COM7, COM8, COM9,     \n" +
        "    COM[1-9]|LPT[1-9]            # LPT1, LPT2, LPT3, LPT4, LPT5,     \n" +
        "  )                              # LPT6, LPT7, LPT8, and LPT9...     \n" +
        "  (?:\\.[^.]*)?                  # followed by optional extension    \n" +
        "  $                              # and end of string                 \n" +
        ")                                # End negative lookahead assertion. \n" +
        "[^<>:\"/\\\\|?*\\x00-\\x1F]*     # Zero or more valid filename chars.\n" +
        "[^<>:\"/\\\\|?*\\x00-\\x1F\\ .]  # Last char is not a space or dot.  \n" +
        "$                                # Anchor to end of string.            ", 
        Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.COMMENTS);
    Matcher matcher = pattern.matcher(text);
    boolean isMatch = matcher.matches();
    return isMatch;
}