I need to show last 4 digits phone number on page which i am going to get from API.
Can you please help me? format should be like (XXX)XXX-1234
Can you be more specific.You can use a pipe for formatting it in desired way.
While your question isn't very specific, you might consider using this: Angular
SlicePipe
That way you can get the last 4 digits of the phone number using string indices.
This is more of a javascript answer, but you could create an expression, then use it in your HTML.
$scope.formatPhone = function(phoneNumber) {
if(phoneNumber) {
return '(XXX)XXX-' + phoneNumber.substr(phoneNumber.length - 4);
}
return '';
}
Related
If you don't mind me asking, I've been trying to find out a way to have a discord user say (prefix)randomnumber and then 2 parameters like 1 10 and it picks a random number such as 7. Does anyone know of a way to do this in java script?
You can do like
Math.floor(Math.random()*second_parameter)+first_parameter
and if we take the full code
const args = message.split(' ')
if(args[0] === `${prefix}randomnumber`){
message.channel.send(Math.floor(Math.random()*parseInt(args[2]))+parseInt(args[1]))
On Selenium, I'm writing script to get the number from the text. suppose there is a field 'Status(2)'. The number in the brackets keep changing. I want to get the value.
This code should get back the text for the element you have provided:
WebElement web_element_found = driver.findElement(By.id("ctl00_ctl00_cphBMain_cphMain_lblObjects"));
String element_text = web_element_found.getText();
Then you can have a look at this answer for how to use regex to extract the digit from the string: Regex to extract digit from string in Java
Hope this helps!
Here is the solution.
String rawText = driver.findElement(By.id("ctl00_ctl00_cphBMain_cphMain_lblObjects")).getText();
String number = rawText.substring(s.indexOf("(") + 1).substring(0, s.indexOf(")"));
System.out.println(number);
How to restrict textbox to allow only numbers and format as US mobile number format in react js ? ex : (456) 125-0156. Below code to allow only numbers.
mobileNumberChange(evt) {
var decimalvalidate = /^[2-9][0-9]*$/;
if (!decimalvalidate.test(evt.key)) {
evt.preventDefault();
}
But how will I format as (456) 125-0156 ?
By the looks of it, you're looking for a regexp to validate US phone numbers, which will be
/^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$/
Refer to this answer for detailed explanation
I am trying to create multiple masked input fields. Angular ui-mask looks like the way to go, however, I can't find very good documentation on the utility. I found an example for credit cards that was very nicely done. I would like to implement this feature in almost exactly the same way, but with 1) phone number 2) decimal 3) percentage 4) email 5) currency, such that the fields are dynamically masked as the user types. My question is how would I go about using ui-mask to accomplish these tasks? Or is there a better way to achieve this? Examples or links to documentation would be appreciated
I guess you can find your answer here:
https://github.com/angular-ui/ui-utils/issues/16
As it is explained in the link a dynamic way is that you can get the mask from a scope/controller variable, check the input and change the mask as needed like:
<input type="text" ui-mask="{{mask}}" ng-keyup="onKeyUp()" ng-model="myinput">
$scope.myinput = '';
var defaultMask = '(99) 9999-9999';
$scope.mask = defaultMask;
$scope.onKeyUp = function(){
if ($scope.myinput.slice(0,3) == '119') { // (11) 9 means mobile, or instead, you could use a regex
$scope.mask = '(99) 99999-9999';
} else {
$scope.mask = defaultMask;
}
};
If I had the following class:
class foo(models.Model):
list = models.CommaSeparatedIntegerField(max_length=255)
If I try to add a foo object from the admin, it will not let me populate list with negative numbers. For instance, if I populate the field with 1,2,3,4 its fine. But 1,2,3,-4 will give me the error message "Enter only digits separated by commas." Any ideas?
Thanks!
The validation code of CommaSeparatedIntegerField looks like this:
comma_separated_int_list_re = re.compile('^[\d,]+$')
validate_comma_separated_integer_list = RegexValidator(comma_separated_int_list_re, _(u'Enter only digits separated by commas.'), 'invalid')
So you can't use it for negative numbers.
I suggest you write your own validation code based on this code.