Rectangle 27 3

There is not an explicit way to check whether two handles refer to the same process. The only way would be to query the process information and check that, e.g. using GetProcessId on each handle to check the process IDs.

If you don't have the necessary access rights to call the desired query functions then you can try calling DuplicateHandle to get a new handle with more access rights. However, if this fails then you have no way of telling whether the handles are to the same process or not.

syntax of DuplicateHandle is below. BOOL WINAPI DuplicateHandle( __in HANDLE hSourceProcessHandle, __in HANDLE hSourceHandle, __in HANDLE hTargetProcessHandle, __out LPHANDLE lpTargetHandle, __in DWORD dwDesiredAccess, __in BOOL bInheritHandle, __in DWORD dwOptions ); dwOptions can get one of two following values (DUPLICATE_CLOSE_SOURCE or DUPLICATE_SAME_ACCESS) or any combination of those.now can i join those values with PROCESS_QUERY_INFORMATION tag.

Set dwOptions as 0, and set dwDesiredAccess to the required access rights (e.g. PROCESS_QUERY_INFORMATION and whatever else you need).

c++ - How to Compare Two variable of HANDLE type - Stack Overflow

c++ winapi process handle
Rectangle 27 3

There is not an explicit way to check whether two handles refer to the same process. The only way would be to query the process information and check that, e.g. using GetProcessId on each handle to check the process IDs.

If you don't have the necessary access rights to call the desired query functions then you can try calling DuplicateHandle to get a new handle with more access rights. However, if this fails then you have no way of telling whether the handles are to the same process or not.

syntax of DuplicateHandle is below. BOOL WINAPI DuplicateHandle( __in HANDLE hSourceProcessHandle, __in HANDLE hSourceHandle, __in HANDLE hTargetProcessHandle, __out LPHANDLE lpTargetHandle, __in DWORD dwDesiredAccess, __in BOOL bInheritHandle, __in DWORD dwOptions ); dwOptions can get one of two following values (DUPLICATE_CLOSE_SOURCE or DUPLICATE_SAME_ACCESS) or any combination of those.now can i join those values with PROCESS_QUERY_INFORMATION tag.

Set dwOptions as 0, and set dwDesiredAccess to the required access rights (e.g. PROCESS_QUERY_INFORMATION and whatever else you need).

c++ - How to Compare Two variable of HANDLE type - Stack Overflow

c++ winapi process handle
Rectangle 27 3

In JavaScript you can compare two variable with type check or without type check

8 == '8' //true /* dont check type*/
 8=== '8'   //false /* check type*/

Since you saying that your code is not working. and value of $("#TemplateId").text() is '8'( shown in console). only possible problem is response.templateId is not equals to 8.

@zerkms his question is : how can I compare then both values?. I gave options for comparison.

==

@zerkms Sorry, I did not consider 'strict mode'.

but still - I don't see how this is helpful. Yes, == compares 2 operands, so?

8 ist not "8" in a javascript comparison - Stack Overflow

javascript
Rectangle 27 187

To compare two objects you can use:

angular.equals(obj1, obj2)

It does a deep comparison and does not depend on the order of the keys See AngularJS DOCS and a little Demo

var obj1 = {
  key1: "value1",
  key2: "value2",
  key3: {a: "aa", b: "bb"}
}

var obj2 = {
  key2: "value2",
  key1: "value1",
  key3: {a: "aa", b: "bb"}
}

angular.equals(obj1, obj2) //<--- would return true

This should be marked as the answer, even does a deep comparison! +1

angular.equals( { id: "12" }, { id: 12 } ) // is false

@bobjones angular.equals returns true based on identity OR deep equality, so your proposed example would return true. see the angular.equals documentation , specifically Two objects or values are considered equivalent if at least one of the following is true

@tommyTheHitMan: bobjones example returns false because, based on identity, "12"===12 // is false. Just try it out.

A quick note: angular.equals() ignores all properties beginning with $, and all properties whose values are functions, when both arguments are objects.

angularjs - Compare objects in Angular - Stack Overflow

angularjs
Rectangle 27 39

You should be able to use ng-pattern/regex for comparing 2 input values

Email:<input type="email" name="email1" ng-model="emailReg">
Repeat Email:<input type="email" name="email2" ng-model="emailReg2" ng-pattern="emailReg">

and validation with:

<span ng-show="registerForm.email2.$error.pattern">Repeat Email should have the same value with email!</span>

It won't work in the following case: email: abc, email2: abcd

it should work but if you are putting 'abc' or 'abcd' as input, those are not valid email addresses which probably failed the validation ahead of going into the pattern validation.

this is close, just put the emailReg inside parentheses, I will add an example below.

This is brilliant. Already implemented a custom directive which is what everyone seems to suggest, but I'm totally ditching it since this feels to me a lot more in tune with the 'Angular way' of doing things!

Of course this fails when u have regex symbols. Also I would expect "test@test.com" to match "test@testacom" so this is a pretty terrible approach. - /test@test.com/.test('test@testacom')

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 39

You should be able to use ng-pattern/regex for comparing 2 input values

Email:<input type="email" name="email1" ng-model="emailReg">
Repeat Email:<input type="email" name="email2" ng-model="emailReg2" ng-pattern="emailReg">

and validation with:

<span ng-show="registerForm.email2.$error.pattern">Repeat Email should have the same value with email!</span>

It won't work in the following case: email: abc, email2: abcd

it should work but if you are putting 'abc' or 'abcd' as input, those are not valid email addresses which probably failed the validation ahead of going into the pattern validation.

this is close, just put the emailReg inside parentheses, I will add an example below.

This is brilliant. Already implemented a custom directive which is what everyone seems to suggest, but I'm totally ditching it since this feels to me a lot more in tune with the 'Angular way' of doing things!

Of course this fails when u have regex symbols. Also I would expect "test@test.com" to match "test@testacom" so this is a pretty terrible approach. - /test@test.com/.test('test@testacom')

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 36

One way to achieve this is with a custom directive. Here's an example using the ngMatch directive:

<p>Email:<input type="email" name="email1" ng-model="emailReg">
Repeat Email:<input type="email" name="email2" ng-model="emailReg2" ng-match="emailReg"></p>

<span data-ng-show="myForm.emailReg2.$error.match">Emails have to match!</span>
ng-

It's also possible to get this functionality without using a custom directive:

<button ng-click="add()></button>
<span ng-show="IsMatch">Emails have to match!</span>
$scope.add = function() {
  if ($scope.emailReg != $scope.emailReg2) {
    $scope.IsMatch=true;
    return false;
  }
  $scope.IsMatch=false;
}

@Why directive for this? you can simply use my code. It's relay easy. otherwise you need manually write some code

Thank you, this is good - and I can still copy the directive from the page you linked and it works as well, so I will see what works best later.

ng-match is not a validation directive that is provided by the AngularJS framework. Please do not name your own custom directives with ng-*. The valid list of existing validators is available at docs.angularjs.org/api/ng/directive/input

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 36

One way to achieve this is with a custom directive. Here's an example using the ngMatch directive:

<p>Email:<input type="email" name="email1" ng-model="emailReg">
Repeat Email:<input type="email" name="email2" ng-model="emailReg2" ng-match="emailReg"></p>

<span data-ng-show="myForm.emailReg2.$error.match">Emails have to match!</span>
ng-

It's also possible to get this functionality without using a custom directive:

<button ng-click="add()></button>
<span ng-show="IsMatch">Emails have to match!</span>
$scope.add = function() {
  if ($scope.emailReg != $scope.emailReg2) {
    $scope.IsMatch=true;
    return false;
  }
  $scope.IsMatch=false;
}

@Why directive for this? you can simply use my code. It's relay easy. otherwise you need manually write some code

Thank you, this is good - and I can still copy the directive from the page you linked and it works as well, so I will see what works best later.

ng-match is not a validation directive that is provided by the AngularJS framework. Please do not name your own custom directives with ng-*. The valid list of existing validators is available at docs.angularjs.org/api/ng/directive/input

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 28

trainosais - you are right, validation should be done on a directive level. It's clean, modular and allows for reusability of code. When you have basic validation like that in a controller you have write it over and over again for different forms. That's super anti-dry.

I had a similar problem recently and sorted it out with a simple directive, which plugs in to the parsers pipeline, therefore stays consistent with Angular architecture. Chaining validators makes it very easy to reuse and that should be considered the only solution in my view.

Without further ado, here's the simplified markup:

<form novalidate="novalidate">
    <label>email</label>
    <input type="text"
        ng-model="email"
        name="email" />
    <label>email repeated</label>
    <input ng-model="emailRepeated"
        same-as="email"
        name="emailRepeated" />
</form>
angular.module('app', [])
    .directive('sameAs', function() {
        return {
            require: 'ngModel',
            link: function(scope, elem, attrs, ngModel) {
                ngModel.$parsers.unshift(validate);

                // Force-trigger the parsing pipeline.
                scope.$watch(attrs.sameAs, function() {
                    ngModel.$setViewValue(ngModel.$viewValue);
                });

                function validate(value) {
                    var isValid = scope.$eval(attrs.sameAs) == value;

                    ngModel.$setValidity('same-as', isValid);

                    return isValid ? value : undefined;
                }
            }
        };
    });

The directive hooks into the parsers pipeline in order to get notified of any changes to the view value and set validity based on comparison of the new view value and the value of the reference field. That bit is easy. The tricky bit is sniffing for changes on the reference field. For that the directive sets a watcher on the reference value and force-triggeres the parsing pipeline, in order to get all the validators run again.

ngModel.$setViewValue(ngModel.$viewValue);
$parsers
validate(ngModel.$viewValue);

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 28

trainosais - you are right, validation should be done on a directive level. It's clean, modular and allows for reusability of code. When you have basic validation like that in a controller you have write it over and over again for different forms. That's super anti-dry.

I had a similar problem recently and sorted it out with a simple directive, which plugs in to the parsers pipeline, therefore stays consistent with Angular architecture. Chaining validators makes it very easy to reuse and that should be considered the only solution in my view.

Without further ado, here's the simplified markup:

<form novalidate="novalidate">
    <label>email</label>
    <input type="text"
        ng-model="email"
        name="email" />
    <label>email repeated</label>
    <input ng-model="emailRepeated"
        same-as="email"
        name="emailRepeated" />
</form>
angular.module('app', [])
    .directive('sameAs', function() {
        return {
            require: 'ngModel',
            link: function(scope, elem, attrs, ngModel) {
                ngModel.$parsers.unshift(validate);

                // Force-trigger the parsing pipeline.
                scope.$watch(attrs.sameAs, function() {
                    ngModel.$setViewValue(ngModel.$viewValue);
                });

                function validate(value) {
                    var isValid = scope.$eval(attrs.sameAs) == value;

                    ngModel.$setValidity('same-as', isValid);

                    return isValid ? value : undefined;
                }
            }
        };
    });

The directive hooks into the parsers pipeline in order to get notified of any changes to the view value and set validity based on comparison of the new view value and the value of the reference field. That bit is easy. The tricky bit is sniffing for changes on the reference field. For that the directive sets a watcher on the reference value and force-triggeres the parsing pipeline, in order to get all the validators run again.

ngModel.$setViewValue(ngModel.$viewValue);
$parsers
validate(ngModel.$viewValue);

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 442

For string comparison, use: if [ "$s1" == "$s2" ] For the a contains b, use: if [[ $s1 == *"$s2"* ]] (and make sure to add spaces between the symbols): bad: if ["$s1" == "$s2"] good: if [ "$s1" == "$s2" ] share|improve this answer edited Dec 5 '16 at 8:26 Alexander Mills 9,0371672167 answered Nov 25 '10 at 13:49 marcog 72.5k37162194
[[ $s1 == *"$s2"* ]]

The picky guys on IRC are telling me you should use if [[ "$s1" == "$s2" ]] or case.

The double equals sign is an error in the first case. Bash tolerates it, but the portable variant is if [ "$s1" = "$s2" ]. See also Rahul's answer

linux - How do I compare two string variables in an 'if' statement in ...

linux bash scripting ubuntu
Rectangle 27 460

For string comparison, use: if [ "$s1" == "$s2" ] For the a contains b, use: if [[ $s1 == *"$s2"* ]] (and make sure to add spaces between the symbols): bad: if ["$s1" == "$s2"] good: if [ "$s1" == "$s2" ] share|improve this answer edited Dec 5 '16 at 8:26 Alexander Mills 9,9161679181 answered Nov 25 '10 at 13:49 marcog 73.9k37164194
[[ $s1 == *"$s2"* ]]

The picky guys on IRC are telling me you should use if [[ "$s1" == "$s2" ]] or case.

The double equals sign is an error in the first case. Bash tolerates it, but the portable variant is if [ "$s1" = "$s2" ]. See also Rahul's answer

linux - How do I compare two string variables in an 'if' statement in ...

linux bash scripting ubuntu
Rectangle 27 11

I recently wrote a custom directive which can be generic enough to do any validation. It take a validation function from the current scope

module.directive('customValidator', [function () {
        return {
            restrict: 'A',
            require: 'ngModel',
            scope: { validateFunction: '&' },
            link: function (scope, elm, attr, ngModelCtrl) {
                ngModelCtrl.$parsers.push(function (value) {
                    var result = scope.validateFunction({ 'value': value });
                    if (result || result === false) {
                        if (result.then) {
                            result.then(function (data) {           //For promise type result object
                                ngModelCtrl.$setValidity(attr.customValidator, data);
                            }, function (error) {
                                ngModelCtrl.$setValidity(attr.customValidator, false);
                            });
                        }
                        else {
                            ngModelCtrl.$setValidity(attr.customValidator, result);
                            return result ? value : undefined;      //For boolean result return based on boolean value
                        }
                    }
                    return value;
                });
            }
        };
    }]);
<input type="email" name="email2" ng-model="emailReg2" custom-validator='emailMatch' data-validate-function='checkEmailMatch(value)'>
<span ng-show="registerForm.email2.$error.emailMatch">Emails have to match!</span>

In you controller then you can implement the method, that should return true or false

$scope.checkEmailMatch=function(value) {
    return value===$scope.emailReg;
}

The advantage is that you do not have to write custom directive for each custom validation.

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 11

I recently wrote a custom directive which can be generic enough to do any validation. It take a validation function from the current scope

module.directive('customValidator', [function () {
        return {
            restrict: 'A',
            require: 'ngModel',
            scope: { validateFunction: '&' },
            link: function (scope, elm, attr, ngModelCtrl) {
                ngModelCtrl.$parsers.push(function (value) {
                    var result = scope.validateFunction({ 'value': value });
                    if (result || result === false) {
                        if (result.then) {
                            result.then(function (data) {           //For promise type result object
                                ngModelCtrl.$setValidity(attr.customValidator, data);
                            }, function (error) {
                                ngModelCtrl.$setValidity(attr.customValidator, false);
                            });
                        }
                        else {
                            ngModelCtrl.$setValidity(attr.customValidator, result);
                            return result ? value : undefined;      //For boolean result return based on boolean value
                        }
                    }
                    return value;
                });
            }
        };
    }]);
<input type="email" name="email2" ng-model="emailReg2" custom-validator='emailMatch' data-validate-function='checkEmailMatch(value)'>
<span ng-show="registerForm.email2.$error.emailMatch">Emails have to match!</span>

In you controller then you can implement the method, that should return true or false

$scope.checkEmailMatch=function(value) {
    return value===$scope.emailReg;
}

The advantage is that you do not have to write custom directive for each custom validation.

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 96

In Expression Language you can just use the == or eq operator to compare object values. Behind the scenes they will actually use the Object#equals(). This way is done so, because until with the current EL 2.1 version you cannot invoke methods with other signatures than standard getter (and setter) methods (in the upcoming EL 2.2 it would be possible).

<c:when test="${lang}.equals(${pageLang})">

should be written as (note that the whole expression is inside the { and })

<c:when test="${lang == pageLang}">
<c:when test="${lang eq pageLang}">

Both are behind the scenes roughly interpreted as

String
<c:when test="${lang == 'en'}">
<c:when test="${lang eq 'en'}">

which is behind the scenes roughly interpreted as

jspContext.findAttribute("lang").equals("en")

I'm assuming I can use test="${lang eq 'en'}" then too? I see eq` up there, but it wasn't with string constants? Just making sure, I don't frequent myself with JSTL/expression language often

@Sucker: eq is an alias for ==. They do both exactly the same. See also operators in EL.

It works EXCEPT in 1 letter String comparison case. Then you should use <c:when test='${lang eq "e"}'> (swap simple for double quotes) struts.apache.org/release/2.0.x/docs/

@exoddus: please don't confuse OGNL with EL.

jsp - How to compare two object variables in EL expression language? -...

jsp operators jstl el object-comparison
Rectangle 27 118

if [ "$s1" == "$s2" ]

Just wanted to say to make sure to leave a space between the beginning and ending square brackets and the "$s1" == "$s2" statement or it will not work. Also, this works too: if test "$s1" = "$s2"

It's all about space :))

linux - How do I compare two string variables in an 'if' statement in ...

linux bash scripting ubuntu
Rectangle 27 7

When upgrading angular to 1.3 and above I found an issue using Jacek Ciolek's great answer:

  • Add the same data to the field with the directive on it (this field is now valid)
  • Go back to the reference field and change the data (directive field remains valid)
var modelToMatch = element.attr('sameAs')
var modelToMatch = attrs.sameAs

To fix this (tested in angular 1.3 and 1.4) I adapted rdukeshier's code and added a watcher on the reference field to run all validations when the reference field is changed. The directive now looks like this:

angular.module('app', [])
  .directive('sameAs', function () {
    return {
      require: 'ngModel',
      link: function(scope, element, attrs, ctrl) {
        var modelToMatch = attrs.sameAs;      

        scope.$watch(attrs.sameAs, function() {
          ctrl.$validate();          
        })

        ctrl.$validators.match = function(modelValue, viewValue) {
          return viewValue === scope.$eval(modelToMatch);
        };
      }
   };
});

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 7

When upgrading angular to 1.3 and above I found an issue using Jacek Ciolek's great answer:

  • Add the same data to the field with the directive on it (this field is now valid)
  • Go back to the reference field and change the data (directive field remains valid)
var modelToMatch = element.attr('sameAs')
var modelToMatch = attrs.sameAs

To fix this (tested in angular 1.3 and 1.4) I adapted rdukeshier's code and added a watcher on the reference field to run all validations when the reference field is changed. The directive now looks like this:

angular.module('app', [])
  .directive('sameAs', function () {
    return {
      require: 'ngModel',
      link: function(scope, element, attrs, ctrl) {
        var modelToMatch = attrs.sameAs;      

        scope.$watch(attrs.sameAs, function() {
          ctrl.$validate();          
        })

        ctrl.$validators.match = function(modelValue, viewValue) {
          return viewValue === scope.$eval(modelToMatch);
        };
      }
   };
});

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 1

This module works well for comparing two fields. Works great with Angular 1.3+. Simple to use https://www.npmjs.com/package/angular-password

It also allows saving the module as a generic. Just include them in packages list of your module.

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation
Rectangle 27 1

This module works well for comparing two fields. Works great with Angular 1.3+. Simple to use https://www.npmjs.com/package/angular-password

It also allows saving the module as a generic. Just include them in packages list of your module.

Comparing two input values in a form validation with AngularJS - Stack...

forms angularjs validation