Rails - How do you stop custom validators from running on optional fields? - ruby-on-rails-3

I have a model called Client which runs a custom phone number validator to see if a given phone number is valid (validates :phone_number, :run_custom_validator => true). The problem is that this phone number field should not be required, its optional, but the validator runs every time even when no phone number is given. How do I get the validator to run only when a phone number is given? Any responses would be much appreciated! Thanks!

In the custom phone number validator, on the first line put the following:
return if phone_number.blank?

Related

How can I add a second phone number in Hubspot?

I tried to add the number in Hubspot to keep the calling recorded however its not working.
Current way: setting- general - calling add phone number
result: no sms, calls received to verify
Does any one know how to do it?

Slack API - Don't notify user when parsing user id

In this message formatting doc: https://api.slack.com/docs/message-formatting, you can use special control sequence characters < and > to perform server-side parsing (server-side as in Slack API's server-side).
So using <#U024BE7LH> in your chat.postMessage() call will get parsed to something like #bob or whatever the username associated with that ID is, in the actual text that shows up in slack.
Unfortunately, this will cause a notification for the person you're referring to. How do I make it so that it doesn't notify the person? I've tried to enclose in a code block, i.e.:
`<#U024BE7LH>`
or
```
<#U024BE7LH>
```
But it still pings. I'm thinking the only way is to get a list of users and parse the name from the ID.
According to this, backticks should work but empirically it hasn't for me. The Slack employee says to just convert the user ID to their name and use that without the templating.
https://forums.slackcommunity.com/s/question/0D73a000005n0OXCAY/detail?language=en_US&fromEmail=1&s1oid=00Dj0000001q028&s1nid=0DB3a000000fxl3&s1uid=0053a00000Ry9cX&s1ext=0&emkind=chatterCommentNotification&emtm=1667894666436&emvtk=fH.W2M01lq9W1cf31RSROPwB7LYs.och8RgbVTqoNlg%3D&t=1667931570045

I am writing test script for mobile number validation, where i have to verify that all characters in mobile field should not be zero.

I am writing test script for mobile number validation, where i have to verify that all characters in mobile field should not be zero. Can someone help me solve this out.
Like so,
String mobileNumber = "1234567890";
if(mobileNumber.matches("(.*?0.*?){5}"))
{
// Number does not pass validation
}

Create custom validation with three different error messages

I need to create a validation on an email field, i am using MVC 4.
I would use a simple regular expression, however as you see below i need to show three different error messages depending of the input on email field.
Validation Rules:
1)If the # sign is not present in the email address, display the message: # sign is required.
2) If no period (.) is entered, display the message: Period (.) after the # sign is required.
3) If 2 characters are not present after the period, display the message: Must contain at least 2 characters after the period.

How to change registration requirement for user ID in chat function

Hi when I run the sample chat function provided by quickblox, it contains several built-in limitation for username registration, for example, I need to have a certain number of characters or type of characters in order to register. I'm wondering which files contain those registration and display of error messages (I only found a class called "errors" in SignUpViewController ) and how do I change those limitations?
There are 2 ways:
Sign Up & then Sign In with email
Sign Up & then Sign In with login - Login field should contain alphanumeric and punctuation characters only
Is it OK? Or you have problem with other User's field?