How can I check whether an item already exists in state?
Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).
const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];
const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];
const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];
const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];
class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);
handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;
switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));
render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)
javascript reactjs
|
show 1 more comment
Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).
const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];
const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];
const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];
const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];
class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);
handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;
switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));
render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)
javascript reactjs
Check out here: regex101.com/r/fFIS01/1
– Masious
Nov 14 '18 at 2:23
That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.
– Hernan Ariel
Nov 14 '18 at 2:26
Can you provide a jsFiddle?
– GMaiolo
Nov 14 '18 at 2:40
Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m
– Hernan Ariel
Nov 14 '18 at 2:53
@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?
– Ramesh
Nov 14 '18 at 3:35
|
show 1 more comment
Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).
const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];
const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];
const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];
const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];
class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);
handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;
switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));
render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)
javascript reactjs
Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).
const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];
const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];
const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];
const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];
class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);
handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;
switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));
render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)
javascript reactjs
javascript reactjs
edited Nov 14 '18 at 3:08
isherwood
37k1082111
37k1082111
asked Nov 14 '18 at 2:16
Hernan ArielHernan Ariel
13817
13817
Check out here: regex101.com/r/fFIS01/1
– Masious
Nov 14 '18 at 2:23
That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.
– Hernan Ariel
Nov 14 '18 at 2:26
Can you provide a jsFiddle?
– GMaiolo
Nov 14 '18 at 2:40
Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m
– Hernan Ariel
Nov 14 '18 at 2:53
@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?
– Ramesh
Nov 14 '18 at 3:35
|
show 1 more comment
Check out here: regex101.com/r/fFIS01/1
– Masious
Nov 14 '18 at 2:23
That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.
– Hernan Ariel
Nov 14 '18 at 2:26
Can you provide a jsFiddle?
– GMaiolo
Nov 14 '18 at 2:40
Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m
– Hernan Ariel
Nov 14 '18 at 2:53
@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?
– Ramesh
Nov 14 '18 at 3:35
Check out here: regex101.com/r/fFIS01/1
– Masious
Nov 14 '18 at 2:23
Check out here: regex101.com/r/fFIS01/1
– Masious
Nov 14 '18 at 2:23
That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.
– Hernan Ariel
Nov 14 '18 at 2:26
That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.
– Hernan Ariel
Nov 14 '18 at 2:26
Can you provide a jsFiddle?
– GMaiolo
Nov 14 '18 at 2:40
Can you provide a jsFiddle?
– GMaiolo
Nov 14 '18 at 2:40
Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m
– Hernan Ariel
Nov 14 '18 at 2:53
Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m
– Hernan Ariel
Nov 14 '18 at 2:53
@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?
– Ramesh
Nov 14 '18 at 3:35
@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?
– Ramesh
Nov 14 '18 at 3:35
|
show 1 more comment
2 Answers
2
active
oldest
votes
In Handle click, try replacing the default to below
handleClick(evt)
const id = evt.target.id;
let result = evt.target.value;
switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".") ).length > 0)
result = "";
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");
return
value
;
);
I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only
– Hernan Ariel
Nov 14 '18 at 3:43
Change the const in result to let
– Ramesh
Nov 14 '18 at 3:52
It sort of works, but it still allows: .+.+. and things like that
– Hernan Ariel
Nov 14 '18 at 3:57
Updated code. pls check
– Ramesh
Nov 14 '18 at 4:07
Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)
– Hernan Ariel
Nov 14 '18 at 4:14
|
show 3 more comments
The method you're looking for is includes
EDIT per your additional information:
var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);
You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.
Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.
– Hernan Ariel
Nov 14 '18 at 3:07
Updated for you
– Jake Roby
Nov 14 '18 at 3:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292245%2fhow-can-i-check-whether-an-item-already-exists-in-state%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In Handle click, try replacing the default to below
handleClick(evt)
const id = evt.target.id;
let result = evt.target.value;
switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".") ).length > 0)
result = "";
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");
return
value
;
);
I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only
– Hernan Ariel
Nov 14 '18 at 3:43
Change the const in result to let
– Ramesh
Nov 14 '18 at 3:52
It sort of works, but it still allows: .+.+. and things like that
– Hernan Ariel
Nov 14 '18 at 3:57
Updated code. pls check
– Ramesh
Nov 14 '18 at 4:07
Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)
– Hernan Ariel
Nov 14 '18 at 4:14
|
show 3 more comments
In Handle click, try replacing the default to below
handleClick(evt)
const id = evt.target.id;
let result = evt.target.value;
switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".") ).length > 0)
result = "";
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");
return
value
;
);
I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only
– Hernan Ariel
Nov 14 '18 at 3:43
Change the const in result to let
– Ramesh
Nov 14 '18 at 3:52
It sort of works, but it still allows: .+.+. and things like that
– Hernan Ariel
Nov 14 '18 at 3:57
Updated code. pls check
– Ramesh
Nov 14 '18 at 4:07
Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)
– Hernan Ariel
Nov 14 '18 at 4:14
|
show 3 more comments
In Handle click, try replacing the default to below
handleClick(evt)
const id = evt.target.id;
let result = evt.target.value;
switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".") ).length > 0)
result = "";
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");
return
value
;
);
In Handle click, try replacing the default to below
handleClick(evt)
const id = evt.target.id;
let result = evt.target.value;
switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;
default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".") ).length > 0)
result = "";
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");
return
value
;
);
edited Nov 14 '18 at 4:06
answered Nov 14 '18 at 3:33
RameshRamesh
9,92623777
9,92623777
I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only
– Hernan Ariel
Nov 14 '18 at 3:43
Change the const in result to let
– Ramesh
Nov 14 '18 at 3:52
It sort of works, but it still allows: .+.+. and things like that
– Hernan Ariel
Nov 14 '18 at 3:57
Updated code. pls check
– Ramesh
Nov 14 '18 at 4:07
Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)
– Hernan Ariel
Nov 14 '18 at 4:14
|
show 3 more comments
I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only
– Hernan Ariel
Nov 14 '18 at 3:43
Change the const in result to let
– Ramesh
Nov 14 '18 at 3:52
It sort of works, but it still allows: .+.+. and things like that
– Hernan Ariel
Nov 14 '18 at 3:57
Updated code. pls check
– Ramesh
Nov 14 '18 at 4:07
Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)
– Hernan Ariel
Nov 14 '18 at 4:14
I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only
– Hernan Ariel
Nov 14 '18 at 3:43
I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only
– Hernan Ariel
Nov 14 '18 at 3:43
Change the const in result to let
– Ramesh
Nov 14 '18 at 3:52
Change the const in result to let
– Ramesh
Nov 14 '18 at 3:52
It sort of works, but it still allows: .+.+. and things like that
– Hernan Ariel
Nov 14 '18 at 3:57
It sort of works, but it still allows: .+.+. and things like that
– Hernan Ariel
Nov 14 '18 at 3:57
Updated code. pls check
– Ramesh
Nov 14 '18 at 4:07
Updated code. pls check
– Ramesh
Nov 14 '18 at 4:07
Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)
– Hernan Ariel
Nov 14 '18 at 4:14
Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)
– Hernan Ariel
Nov 14 '18 at 4:14
|
show 3 more comments
The method you're looking for is includes
EDIT per your additional information:
var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);
You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.
Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.
– Hernan Ariel
Nov 14 '18 at 3:07
Updated for you
– Jake Roby
Nov 14 '18 at 3:15
add a comment |
The method you're looking for is includes
EDIT per your additional information:
var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);
You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.
Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.
– Hernan Ariel
Nov 14 '18 at 3:07
Updated for you
– Jake Roby
Nov 14 '18 at 3:15
add a comment |
The method you're looking for is includes
EDIT per your additional information:
var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);
You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.
The method you're looking for is includes
EDIT per your additional information:
var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);
You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.
edited Nov 14 '18 at 3:14
answered Nov 14 '18 at 3:05
Jake RobyJake Roby
5,28011226
5,28011226
Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.
– Hernan Ariel
Nov 14 '18 at 3:07
Updated for you
– Jake Roby
Nov 14 '18 at 3:15
add a comment |
Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.
– Hernan Ariel
Nov 14 '18 at 3:07
Updated for you
– Jake Roby
Nov 14 '18 at 3:15
Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.
– Hernan Ariel
Nov 14 '18 at 3:07
Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.
– Hernan Ariel
Nov 14 '18 at 3:07
Updated for you
– Jake Roby
Nov 14 '18 at 3:15
Updated for you
– Jake Roby
Nov 14 '18 at 3:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292245%2fhow-can-i-check-whether-an-item-already-exists-in-state%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check out here: regex101.com/r/fFIS01/1
– Masious
Nov 14 '18 at 2:23
That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.
– Hernan Ariel
Nov 14 '18 at 2:26
Can you provide a jsFiddle?
– GMaiolo
Nov 14 '18 at 2:40
Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m
– Hernan Ariel
Nov 14 '18 at 2:53
@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?
– Ramesh
Nov 14 '18 at 3:35