xxxxxxxxxx
export const onlyNumbersAndLetters = (value) => {
if(value)
return value.replace(/[^a-zA-Z0-9]/g, '');
}
xxxxxxxxxx
console.log(`12331: ${/^\d+$/.test('12331')}`) // true
console.log(`abc: ${/^\d+$/.test('abc')}`) // false
xxxxxxxxxx
import re
# Regular expression to match only numbers
regex = r'^\d+$'
# Test cases
tests = ['123', '56789', '0', '12a34', 'abc']
for test in tests:
if re.match(regex, test):
print(f"{test} is a number")
else:
print(f"{test} is not a number")
xxxxxxxxxx
import re
text = "abc123xyz456"
numbers_only = re.findall(r'\d+', text)
print(numbers_only)