How do I make Phone number a fixed pattern

colingbradley
Member Posts: 162
If the user enters 9 digits: 01202345678 I need it to be changed to 10202 345678 (5 characters + space + 6 characters)
The problem is to know where to enter the code.
The On Validate is not good as if the field is changed by code, it triggers the code again.
I can run the code after leaving the record bit is it possible to do it as the user is entering more data?
My code works only if the user enters 9 characters and no space but not if they enter the 5 space 6 format, it then errors.
Function: formatphonenumber(phonenumber : Text[30]) : Text[30]
space := COPYSTR(phonenumber,6,1);
IF space <> '' THEN BEGIN
five := COPYSTR(phonenumber,1,5);
six := COPYSTR(phonenumber,6,18);
NewNumber := five + ' ' + six;
EXIT(NewNumber)
END ELSE
EXIT(phonenumber);
The problem is to know where to enter the code.
The On Validate is not good as if the field is changed by code, it triggers the code again.
I can run the code after leaving the record bit is it possible to do it as the user is entering more data?
My code works only if the user enters 9 characters and no space but not if they enter the 5 space 6 format, it then errors.
Function: formatphonenumber(phonenumber : Text[30]) : Text[30]
space := COPYSTR(phonenumber,6,1);
IF space <> '' THEN BEGIN
five := COPYSTR(phonenumber,1,5);
six := COPYSTR(phonenumber,6,18);
NewNumber := five + ' ' + six;
EXIT(NewNumber)
END ELSE
EXIT(phonenumber);
Experience is what you get when you hoped to get money
0
Answers
-
Depending on NAV version you can use:
1. Regular expression to match user input against your format (let users to enter phone number in right format)
2. Use addon to show required pattern and lead users to fill it0 -
1. Regular expression to match user input against your format (let users to enter phone number in right format)
I like the idea of using regular expression to do this, I would think OnValidate would be the place to do this, I don't understand why that would not work.
There are plenty of instructions online on how to format phone numbers in .NET , for instance I would think the c# example in the following link would be plug and play in Nav.
https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s02.html
0 -
OnValidate trigger is right place, but you would create a function, because check and format phone number is a common functionality for multiple fields and is better to call a function then drop the same code to each trigger.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions