JavaScript Custom Javascript Validation without using map,filter custom javascript validation,custom javascript validation mvc,javascript custom validation

I have function for validation for check below scenarios, but function used map and filter methods. so its not working in IE8.How to rewrite this function without using map and filter.

var case1 = "stack(2),flow(2),over(4),temp(7)"; - true
var case2 = "stack(2),flow(3),over(4),temp(k)"; - false
var case3 = "stack(2),flow(2),over(4),temp(0"; - false
var case4 = "stack(2),flow(2),over(,temp)"; - false
var case5 = "stack(2),flow(2),over(4)temp(8)"; - false
var case6 = "stack(1),flow(7),over,temp"; - true
var case7 = "stack(1),flow(7),OVER,Temp"; - true
var case8 = "stack(1),flow(7),over_r,temp_t"; - true

Javascript function :

function validateChunk(s)
{
    return !!s.match(/^[a-z]+(?:\(\d+\))?$/);
}

function filterValid(v)
{
    return !v;
}

function testCases(str)
{
    var chunks = str.split(",");
    var validated = chunks.map(validateChunk);
    return (0 === validated.filter(filterValid).length);

}

jsfiddle

Answer:1

One possible approach is to call validateChunk function in a loop:

for (var i = 0, l = chunks.length; i < l; i++) {
  if (! validateChunk(chunks[i])) {
    return false;
  }
}
return true;

As a sidenote, there's exactly zero sense to use .match when .test clearly suffices (as you don't have to collect the results of match). So I'd rewrite the function like this:

function validateChunk(str) {
  return /^[a-z]+(?:\(\d+\))?$/.test(str);
}

Finally, can't help noticing that all this validation can be done with a single regex:

function testCases(str)
{
    var pattern = /^[a-z]+(?:\(\d+\))?(?:,[a-z]+(?:\(\d+\))?)*$/
    return pattern.test(str);
}

Actually, judging from your description, the pattern should be slightly different: first, _ symbol is valid one and should be included to character class; second, the same class should either include A-Z range as well, or instead a pattern should be given /i modififer. This demo includes all these changes.

Answer:2

Context: I'm trying to make sure that an object passed to a function is valid before I use it. And I'd like to know if there is any difference between the two approaches, one is more syntactically ...

Context: I'm trying to make sure that an object passed to a function is valid before I use it. And I'd like to know if there is any difference between the two approaches, one is more syntactically ...

  1. determine object type python
  2. determine object type in r
  3. determine object type javascript
  4. determine object type java
  5. determine object type c#
  6. determine object type vba
  7. determine object size from picture
  8. determine objectives
  9. determine object type matlab
  10. determine object type powershell
  11. determine objectives spiral model
  12. determine objective function
  13. determine object type from id salesforce
  14. determine object class python
  15. determine object class r
  16. determine object type php
  17. determine object class java
  18. determine object size python
  19. determine object size javascript
  20. determine object height

<input id="phone" name="phone" placeholder="(XXX)XXX-XXXX" type="tel" pattern="^(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}$" required="true"/> How can I validate if that pattern is used in ...

<input id="phone" name="phone" placeholder="(XXX)XXX-XXXX" type="tel" pattern="^(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}$" required="true"/> How can I validate if that pattern is used in ...

  1. validate regex
  2. validate regex online
  3. validate regex javascript
  4. validate regex java
  5. validate regex c#
  6. validate regex php
  7. validate regex python
  8. validate regex js
  9. validate regex laravel
  10. validate regex online java
  11. validate regex pattern
  12. validate regex jquery
  13. validate regex expression
  14. validate regex rails
  15. validate regex angular
  16. validate regex c# online
  17. validate regex javascript online
  18. validate regex jsf
  19. validate regex typescript
  20. validate regex email

I am currently working on some IE11 compatibility issues. The code is fully functional in compatibility mode as it was previously optimize last for IE5. The affected code is as follows: /* * This ...

I am currently working on some IE11 compatibility issues. The code is fully functional in compatibility mode as it was previously optimize last for IE5. The affected code is as follows: /* * This ...

  1. javascript runtime error '$' is undefined
  2. javascript runtime error function is undefined
  3. javascript runtime error 'jquery' is undefined
  4. javascript runtime error access is denied
  5. javascript runtime error function expected
  6. javascript runtime error 'promise' is undefined
  7. javascript runtime error '__dopostback' is undefined
  8. javascript runtime error invalid character
  9. javascript runtime error 'sys' is undefined
  10. javascript runtime error 'angular' is undefined
  11. javascript runtime error object expected
  12. javascript runtime error out of stack space
  13. javascript runtime error 'json' is undefined
  14. javascript runtime error example
  15. javascript runtime error expected ' '
  16. javascript runtime error 'require' is undefined
  17. javascript runtime error argument not optional
  18. javascript runtime error 'google' is undefined
  19. javascript runtime error hierarchyrequesterror
  20. javascript runtime error invalid template

While implementing angularjs directive i have got some issues in sharing controller between directive i cant access the enterUser directive from the below controller app.directive('entires', [...

While implementing angularjs directive i have got some issues in sharing controller between directive i cant access the enterUser directive from the below controller app.directive('entires', [...

  1. angularjs sharing controller between views
  2. angularjs sharing controller
  3. angularjs sharing same controller