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