Rickyrock
Rickyrock

Reputation: 328

Retrieve substring from given string

This question is related to login. This answer may be simple but still 30 mins I am trying using jquery OR javascript.

Given string Example :

john123,ricky43567,jecobs2 and many more like this

Retrieve only character from it.

above string result will be like..

john,ricky,jecobs

Thanks in advance.

Upvotes: 0

Views: 94

Answers (4)

Vishal Suthar
Vishal Suthar

Reputation: 17183

Try a regex

[^a-z,]

So it would be:

var str = 'john123,ricky43567,jecobs2';

var result = str.replace(/[^a-z,]/ig, '')

Regex Demo

JSFiddle Demo

Upvotes: 0

Manish Jangir
Manish Jangir

Reputation: 505

try this one

var str = 'john123,ricky43567,jecobs2';
  myString = str.replace(/(\d+)/g,'');
   alert(myString);

Upvotes: 0

Adil Shaikh
Adil Shaikh

Reputation: 44740

var str = 'john123,ricky43567,jecobs2';
str = str.replace(/\d/g,'');

Demo --> http://jsfiddle.net/zYfWc/2/

Output --> john,ricky,jecobs

Upvotes: 2

Arun P Johny
Arun P Johny

Reputation: 388316

Try a regex like, have look at regular expression

var x = 'john123,ricky43567,jecobs2'.replace(/[^a-z,]/ig, '')

Upvotes: 2

Related Questions