adsense

Tuesday, September 25, 2018

regex to validate HH:MM AM/PM

Following regex can be used to validate HH:MM AM/PM  time format.

^([0-1]?[0-9]|2[0-3]):[0-5][0-9] [APap][mM]$

e.g
Assuming the timper control has provided class "tod"  following code will validate time when user enters a value and tabbed out/focus out from the control.

Javascript
<script  type="text/javascript">

funciton pageLoad(){
  $(".tod").focusout(function (e) {
            if (e.target.value.trim() !== "") {
                var result = checkTime(e.target.value.trim());
                if (!result) {
                   //invalid time
                }
                else {
                   //clear validation
                }
            }
            else {
                 //clear validation
            }
        });
}

function checkTime(value) {
        var pattern = new RegExp("(^([0-1]?[0-9]|2[0-3]):[0-5][0-9] [APap][mM]$)");
        var result = pattern.test(value);
        return result;
    }

</script>



cheers,
Samitha

Thursday, September 6, 2018

NuGet Package restore failed

If you ever encounter this error  delete all the related packages will resolve this.

I will further explain this using an example.

Suppose you get this error for Microsoft.Bcl.Build.Tasks.dll as shown below.

NuGet Package restore failed for project MyProject.Application: The process cannot access the file 'C:\MySolution\packages\Microsoft.Bcl.Build.1.0.21\build/Microsoft.Bcl.Build.Tasks.dll' because it is being used by another process..

This can be resolved by deleting all the Microsoft.Bcl.* folders in the packages under the solution.

Regards,
Samitha

Friday, August 17, 2018

Find an element based on data- value

There are situations where we want to find element based on data- attributes. For instance we have to set validation message at run time for a given field.

In these situations we can use jQuery to easily find an element based on the  data- atttibutes as shown below.

 $('span[data-valmsg-for="' + fieldName + '"]');


cheers,
Samitha


Monday, August 13, 2018

jQuery checkbox OnChange

We can use jQuery to identify checkbox state change as shown below.

<script  type="text/javascript">

 funciton pageLoad() //can use either DOM Ready or pagLoad
{

   const chkSelectAll= $("#chkSelectAll");

   chkSelectAll.change(function(event) {
             var chkBox= event.target;
             if (chkBox.checked) {
               //Checkbox is checked
            } else {
              //Checkbox is unchecked
           }
});

}
</script>
Cheers,
Samitha

Tuesday, July 31, 2018

Get Total Checkboxes using jQuery

Suppose there are several check boxes which are either checked or unchecked. jQury can be used to easily get the number of all check boxes, checked and unchecked boxes as shown below.

var totalCheckboxes = $('input:checkbox').length;
var totalChecked = $('input:checkbox:checked').length;
var totalUnChecked = totalCheckboxes - totalChecked ;

 

Cheers,
Samitha

Thursday, July 26, 2018

jquery Find all elements containing part of an ID

We can use jQuery to find all  elements that starts with of characters as shown below

  $("[id*=_visible_]").each(function(element){
     element.val(''); // do something with the found element.
});

Cheers,
Samitha

Thursday, July 19, 2018

Create an insert script using SELECT

There are many third party tools that provides this feature, but you can use a simple
select statement  easily create an insert script as shown belowe.

Suppose you have employee table  and want to use it to generate data for another table.


select 'insert into Table1 values(' + Id + ', ' + name + ')' from employee


Cheers,
Samitha