How to Parse and Validate a Name in Ruby
If your website or application leverages online sign-up capabilities, ensuring your system can check user inputs, such as name values, for validity is a crucial component. By utilizing the following API in Ruby, you will be able to automatically parse a full name string into its component parts and check whether it’s a valid name string or not.
To start the process, we will add the Ruby client to our Gemfile:
gem 'cloudmersive-validate-api-client', '~> 2.1.6'
Then, we can call the function with the following code:
# load the gem
require 'cloudmersive-validate-api-client'
# setup authorization
CloudmersiveValidateApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
endapi_instance = CloudmersiveValidateApiClient::NameApi.newinput = CloudmersiveValidateApiClient::FullNameValidationRequest.new # FullNameValidationRequest | Validation request informationbegin
#Parse and validate a full name
result = api_instance.name_validate_full_name(input)
p result
rescue CloudmersiveValidateApiClient::ApiError => e
puts "Exception when calling NameApi->name_validate_full_name: #{e}"
end
The end result is the name string separated into its component parts (i.e. first name, last name, suffix, etc.) accompanied by the validity status. Mission accomplished.