-4

I have a string

var houseNumber = '13a';

I want to split the addition from the number so I can keep it in a other field. How can I split this value without losing the number or the addition? At the end I would like to have 2 fields with the following type:

var houseNumber = 13; //Number
var addition = 'a'; //String

There are many questions about this, but I can't find one where both values has to be saved. That's why I created a new question.

NVO
  • 2,566
  • 5
  • 27
  • 57

1 Answers1

2

Use the following code

var string_a = "jkjkhj89898";
var x = string_a.match(/[^\d]+|\d+/g);
console.log(x)

working fiddle.

Thanks

user3775217
  • 4,675
  • 1
  • 22
  • 33
  • Please you should not answer a question that is duplicate. Soon you will earn privilege to close a question. Once you have it, please choose to close instead of answering a duplicate. – Rajesh Jan 18 '17 at 09:52
  • sorry i refreshed the page later, then it was marked duplicate. – user3775217 Jan 18 '17 at 09:53
  • When you see a basic question, there is a high possibility that this has been answered before. So you should search for these questions and if found, mark it as dupe or add a comment `Possible Duplicate ` so someone else can do it. Also there is no need for *sorry*. We all learn gradually. :-) – Rajesh Jan 18 '17 at 09:55