Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @pattern support for constraint package #3179

Closed
shafreenAnfar opened this issue Jul 28, 2022 · 3 comments · Fixed by ballerina-platform/module-ballerina-constraint#29
Closed
Assignees
Labels
module/constraint Points/2.5 Team/PCM Protocol connector packages related issues Type/Improvement
Milestone

Comments

@shafreenAnfar
Copy link
Contributor

This was not implemented due to no support for Regex in the language.

#2850

@shafreenAnfar shafreenAnfar added Type/Improvement Team/PCM Protocol connector packages related issues module/constraint labels Jul 28, 2022
@shafreenAnfar shafreenAnfar moved this to Standard Lib - PCM in Swan Lake Update 3 Jul 28, 2022
@shafreenAnfar shafreenAnfar changed the title Add @pattern support for constraint package Add @pattern support for constraint package Aug 1, 2022
@TharmiganK
Copy link
Contributor

Required support issue : ballerina-platform/ballerina-spec#130

@chamil321 chamil321 moved this to Standard Lib - PCM in Swan Lake Update 3 Sep 27, 2022
@daneshk daneshk moved this to Standard Lib - PCM in Swan Lake Update 3 Sep 27, 2022
@TharmiganK
Copy link
Contributor

The regex support is now given in the language : https://ballerina.io/spec/lang/master/#lang.regexp

Example usage for pattern matching :

import ballerina/io;

public function main() {
    // Defining a regular expression
    string:RegExp regExp = re `[0-9]*`;

    string testString1 = "0123456789";
    string testString2 = "012345ab";

    if regExp.isFullMatch(testString1) {
        io:println("Test string 1 is a full match");
    } else {
        io:println("Test string 1 is not a full match");
    }

    if regExp.isFullMatch(testString2) {
        io:println("Test string 2 is a full match");
    } else {
        io:println("Test string 2 is not a full match");
    }
}

Applying pattern constraint using the constraint module :

import ballerina/constraint;

string:RegExp regExp = re `[^0-9]*`;

@constraint:String {
    length: 10,
    pattern: regExp
}
type PhoneNumber string;

type User record {|
    string name;
    int age;
    @constraint:String {
        pattern: re `([0-9]{9}[v|V]|[0-9]{12})`
    }
    string nic;
    string address;
    PhoneNumber contactNumber;
|};

@TharmiganK
Copy link
Contributor

Found a blocker in the runtime : ballerina-platform/ballerina-lang#38336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/constraint Points/2.5 Team/PCM Protocol connector packages related issues Type/Improvement
Projects
Archived in project
Status: Standard Lib - PCM
Development

Successfully merging a pull request may close this issue.

2 participants